where 查询相关的问题
代码:
->when($title, function ($query) use ($title)
{
return $query->where('title', 'like', sprintf('%%%s%%', $title))->orWhere('id', $title);
})
需求:
当前 Sql:
select * from `iblue_posts` where (`title` like ? or `id` = ? and `created_at` >= ? and `state` = ?) and `iblue_posts`.`deleted_at` is null order by `id` desc limit 20 offset 0
代码怎么改才能让SQL变成:
select * from `iblue_posts` where ((`title` like ? or `id` = ? )and `created_at` >= ? and `state` = ?) and `iblue_posts`.`deleted_at` is null order by `id` desc limit 20 offset 0
推荐文章: