今天在该别人代码时遇到这个问题,首先在SQL查询外写好where()条件,然后SQL语句如下。 使用了匿名函数,用 use 引用匿名函数的外部变量
SELECT * FROM `ny_information`
WHERE `status` = 1
AND (`username` LIKE '%1111%'
OR `cert_number` LIKE '%1111%'
OR `username` LIKE '%1111%')
ORDER BY input_time desc LIMIT 0,8
$whereOr = ' ';//已经给其赋了where条件
$where_1 = ' ';
$where_2 = ' ';
$info = Db::table('ny_information')
->where('status', '=', 1) //where whereOr
//匿名函数用法
->where(function($query) use ($where_1, $whereOr, $where_2){
$query->where($where_1)
->whereOr($whereOr)
->whereOr($where_2);
})
->order("input_time desc")
->paginate(8,false,['query' => request()->param()]);