Multiple column with same search string in laravel

前端 未结 3 1955
余生分开走
余生分开走 2021-01-21 23:24
SELECT * 
FROM table_name 
WHERE 
    CONCAT(id,name, address) LIKE \'%same_string%\' 

What is an alternate query for this in Laravel

3条回答
  •  遥遥无期
    2021-01-22 00:04

    ** Laravel - The general search in multiple columns the in single input

    **

    one of the user table in the first name, last name, job title column available and I have one input search in any value enter then find all column in associated data fetch and display

     $searchQuery = trim($request->query('search'));
     $requestData = ['firstname', 'lastname', 'job_title'];
      $user = User::where(function($q) use($requestData, $searchQuery) {
                            foreach ($requestData as $field)
                               $q->orWhere($field, 'like', "%{$searchQuery}%");
                    })->get();
    

提交回复
热议问题