1$searchTerm ='milad zamir Abc';
2$reservedSymbols = ['-', '+', '<', '>', '@', '(', ')', '~'];
3$searchTerm = str_replace($reservedSymbols, ' ', $searchTerm);
4
5$searchValues = preg_split('/\s+/', $searchTerm, -1, PREG_SPLIT_NO_EMPTY);
6
7$res = User::where(function ($q) use ($searchValues) {
8 foreach ($searchValues as $value) {
9 $q->orWhere('name', 'like', "%{$value}%");
10 $q->orWhere('family_name', 'like', "%{$value}%");
11 }
12})->get();
1The find Method
2If you are overriding the find method in your own models and calling parent::find() within your custom method, you should now change it to call the find method on the Eloquent query builder:
3
4public static function find($id, $columns = ['*'])
5{
6 $model = static::query()->find($id, $columns);
7
8 // ...
9
10 return $model;
11}