where like in laravel eloquent code example
Example 1: where like laravel
User::query()
->where('name', 'LIKE', "%{$searchTerm}%")
->orWhere('email', 'LIKE', "%{$searchTerm}%")
->get();
reference:
https:
Example 2: add like and equal in same query in laravel
$data = DB::table('borrowers')
->join('loans', 'borrowers.id', '=', 'loans.borrower_id')
->select('borrowers.*', 'loans.*')
->where('loan_officers', 'like', '%' . $officerId . '%')
->where('loans.maturity_date', '<', date("Y-m-d"))
->get();
Example 3: laravel where like
$users = DB::table('users')
->where('name', 'like', 'T%')
->get();
Example 4: laravel wherein like
$admin_permissions = Permission::all();
$teacher_permissions = $admin_permissions->filter(function ($permission) {
return substr($permission->title, 0, 8) == 'teacher_';
});