Reputation: 9247
I'm using this query:
public function autocomplete(Request $request)
{
$company_name = $request->input('query');
$data = BusinessUser::where("company_name","LIKE",'%'. $company_name .'%')->pluck('company_name');
return response()->json($data);
}
In database for company name i can have this: 'Test','TEST','test'. So how can i check all of this so that i get result. Any suggestion?
I tried this but then i get an error that i need to pass array:
$data = BusinessUser::whereRaw("company_name","LIKE",'%'. $company_name .'%')->orWhereRaw("company_name","LIKE",'%'. $company_name .'%')->pluck('company_name');
EDIT:
I dont want to change anything in database
Upvotes: 3
Views: 6796
Reputation: 139
Here is an answer without using whereRaw
:
use DB;
$data = BusinessUser::where(DB::raw('LOWER(company_name)'), 'like', '%' . strtolower($company_name) . '%');
Upvotes: 1
Reputation: 163948
You can use LOWER
:
BusinessUser::whereRaw('LOWER(`company_name`) like ?', ['%'.strtolower($company_name).'%'])->pluck('company_name');
Upvotes: 6
Reputation: 1202
Your query should look like this:
$data = BusinessUser::whereRaw("company_name COLLATE UTF8_GENERAL_CI LIKE %{$company_name}%")->pluck('company_name');
Upvotes: 0
Reputation: 11340
Set an encoding for company_name
to utf8_general_ci
. CI
means Case-Insensitive.
Upvotes: 0