2015-10-17 48 views
2

此查询工作 喜欢LARAVEL口才与多个条件

$conditions = [ 
     'status' => '1', 
     'country' => "DK" 
    ]; 
     $offers = Offers::where($conditions)->get(); 

如何使用LIKE %%在此

当我想这在单一的条件,其工作

 $offers = Offers::where('country' , 'LIKE' , '%DK%')->get(); 

+1

添加更多'where'调用? 'where'('country','LIKE','%DK%') - > where('something','LIKE','%condition%')'也许? –

回答

4

你试过这个吗?

$conditions = [ 
    'status' => '1', 
    'country' => "DK" 
]; 
$offers = Offers::where('country' , 'LIKE' , '%DK%')->where($conditions)->get(); 

您可以根据需要链接您的where子句。

0

其实你可以使用其中多次,所以你可以尝试这样的:

$offers = Offers::where('country' , 'LIKE' , '%DK%') 
    ->where('status', 1) 
    ->get(); 

我没有测试这一点,但你也可以尝试这样的:(它可能工作,但我注意到肯定)

$conditions = [ 
    'status' => '1', 
    'country' => "LIKE %DK%" 
]; 
$offers = Offers::where($conditions)->get(); 
+1

我也不确定,但我认为在条件数组中包含'LIKE'可能会导致SQL注入转义出现问题。 –

+0

也许最好的办法是用多个轮子 –