[英]MYSQL query for Where clause with OR & AND in LARAVEL
I want to select subcategories where categories_id is 31 or 211 or 18 and where status is on and mode is also on.我想选择子类别,其中 categories_id 为 31 或 211 或 18 并且状态为开且模式也为开。
I tried this but I error我试过了,但我出错了
$subcategories =DB::table('subcategories')
->where('categories_id','31')
->orWhere('categories_id','211')
->orWhere('categories_id','18')
->where('status','on')
->where('mode','on')
->get();
You have to use function:你必须使用功能:
$subcategories =DB::table('subcategories')
->where(function($query)
{
$query->where('categories_id', '31')
->orWhere('categories_id', '211')
->orWhere('categories_id', '18');
})
->where('status','on')
->where('mode','on')
->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.