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
You can use LOWER:
BusinessUser::whereRaw('LOWER(`company_name`) like ?', ['%'.strtolower($company_name).'%'])->pluck('company_name');
Here is an answer without using whereRaw:
use DB;
$data = BusinessUser::where(DB::raw('LOWER(company_name)'), 'like', '%' . strtolower($company_name) . '%');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With