我有以下查询,我想知道这是否可能在laravel的QueryBuilder的:laravel查询生成器或内部,其中
SELECT * FROM table WHERE (column = value OR column = value2) AND column2 LIKE '%value3%'
我有以下查询,我想知道这是否可能在laravel的QueryBuilder的:laravel查询生成器或内部,其中
SELECT * FROM table WHERE (column = value OR column = value2) AND column2 LIKE '%value3%'
你的查询应该是这样的:
DB::table('table')
->where(function($q) use ($value, $value2) {
$q->where('column', $value)
->orWhere('column', $value2);
})
->where('column2', 'like', '%'.%value3.'%')
->get();
如果你有多个值,你可以把它们放到一个简单的数组中,并使用whereIn()
:
DB::table('table')
->whereIn('column', $valuesArray)
->where('column2', 'like', '%'.%value3.'%')
->get();
可以将此根据做,使所需的查询
DB::table('table_name')
->where('column', 'value1')
->orWhere('column', 'value2')
->where('column2', 'like', '%value3%');
你可以在那里使用闭包。
\DB::table('table_name')
->where(function($q){
$q->where('column', 'value1')
->orWhere('column', 'value2');
})
->where('column2', 'LIKE', '%value3%');
不会产生分组的表达,而是会在查询,而括号中添加或条件 –