Laravel查询构建器在多列中进行比较

时间:2017-09-26 08:23:13

标签: laravel multiple-columns where-clause query-builder

我正在使用带有laravel的查询构建器,并且我试图获得等效的

--fork
查询构建器中的

?我怎么能得到相同的结果?

3 个答案:

答案 0 :(得分:1)

你可以在whereRaw()这样做

DB::table('emp')->whereRaw("name+' '+firstname LIKE '%test%'")->select('name', 'firstname')->get();

希望它为你工作!

答案 1 :(得分:1)

 $result = DB::table('emp')->select('name', 'firstname')->where(DB::raw("CONCAT('name', ' ', 'firstname')"), 'LIKE', '%'. 'test' .'%')->get();

答案 2 :(得分:0)

尝试将CONCAT用于多列

DB::table('emp')->Where(DB::raw("CONCAT(`name`, ' ', `firstname`)"), 'LIKE', "%test%")->select('name', 'firstname')->get();
希望这会有所帮助。