此查询工作 喜欢LARAVEL口才与多个条件
$conditions = [
'status' => '1',
'country' => "DK"
];
$offers = Offers::where($conditions)->get();
如何使用LIKE %%在此
当我想这在单一的条件,其工作
$offers = Offers::where('country' , 'LIKE' , '%DK%')->get();
此查询工作 喜欢LARAVEL口才与多个条件
$conditions = [
'status' => '1',
'country' => "DK"
];
$offers = Offers::where($conditions)->get();
如何使用LIKE %%在此
当我想这在单一的条件,其工作
$offers = Offers::where('country' , 'LIKE' , '%DK%')->get();
你试过这个吗?
$conditions = [
'status' => '1',
'country' => "DK"
];
$offers = Offers::where('country' , 'LIKE' , '%DK%')->where($conditions)->get();
您可以根据需要链接您的where子句。
其实你可以使用其中多次,所以你可以尝试这样的:
$offers = Offers::where('country' , 'LIKE' , '%DK%')
->where('status', 1)
->get();
我没有测试这一点,但你也可以尝试这样的:(它可能工作,但我注意到肯定)
$conditions = [
'status' => '1',
'country' => "LIKE %DK%"
];
$offers = Offers::where($conditions)->get();
我也不确定,但我认为在条件数组中包含'LIKE'可能会导致SQL注入转义出现问题。 –
也许最好的办法是用多个轮子 –
添加更多'where'调用? 'where'('country','LIKE','%DK%') - > where('something','LIKE','%condition%')'也许? –