Laravel - 如何在where子句中编写多个条件?

时间:2017-08-30 09:48:43

标签: laravel laravel-5 laravel-5.3

其实我的查询是:

SELECT * FROM company WHERE status<>$status AND type=$b1 AND type=$b2

如何在laravel中转换它?

我在laravel中做到了这一点,但它无法正常工作:

$data['Company'] = DB::table('company')->where([["status","<>",$status], ["type","=",$b1],["type","=",$b2]])->get();

请帮助我!

4 个答案:

答案 0 :(得分:1)

$data['company'] = DB::table('company')->where('status',$status)->where('type',$b1)->where('type',$b2)->get();

答案 1 :(得分:1)

你应该在1条件中使用where方法

$data['Company'] = DB::table('company')->where('status','<>',$status)->where('t‌​ype',$b1)->where('ty‌​pe',$b2)->get();

答案 2 :(得分:1)

试试这个:

\App\Company::where('status','!=',$status)->where('type',$b1)->where('type',$b2)->get();

答案 3 :(得分:1)

whereIn 方法验证给定列的值是否包含在给定数组中:

  

$ data ['Company'] = DB :: table('company')                      - 化合物其中( '状态', '&LT;&GT;',$状态)                      - &GT;其中( '类型',[ '$ B1', '$ B2')                      - &GT;得到();

相关问题