Multiple column with same search string in laravel

前端 未结 3 1951
余生分开走
余生分开走 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-21 23:48

    Try this.

    $field = ['name','id','address'];
    $name = DB::Table('bookinfo')->Where(function ($query) use($string, $field) {
                 for ($i = 0; $i < count($field); $i++){
                    $query->orwhere($field, 'like',  '%' . $string .'%');
                 }      
            })->get();
    

提交回复
热议问题