[英]Laravel , Search Case Insensitive
I'm trying to do a search however i'm having problem with the case sensitivity, how can i make it more case insensitive.我正在尝试进行搜索,但是我在区分大小写方面遇到了问题,我怎样才能让它更不区分大小写。
$query->where(function($query) use ($service_name) {
$query->where('users.options->company_name', 'LIKE', '%' . $service_name . '%');
});
i tried using something like this since this was suggested to me however it doesn't solve my problem.我尝试使用这样的东西,因为这是向我建议的,但它并没有解决我的问题。
$query->where(function($query) use ($service_name) {
$query->where('LOWER(users.options->company_name)', 'LIKE', '%' . strtolower($service_name) . '%');
});
I see you have json column,我看到你有 json 列,
$query->whereRaw("users.options->company_name like '%".$service_name."%'", [$service_name]);
This should solve your problem这应该可以解决您的问题
Because of the json column因为json列
$query->whereRaw("LOWER(users.options->'$.company_name') LIKE LOWER('%$service_name%')");
You can use LOWER/UPPER to resolve case sensitive problem.
您可以使用LOWER/UPPER来解决区分大小写的问题。
syntax to use key of the json column is column->'$.json_key'
使用 json 列的键的语法是
column->'$.json_key'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.