【发布时间】:2019-01-01 19:21:20
【问题描述】:
我想咨询以下问题。
select * from `items`
where (`item_name` LIKE 'foo' or `item_description` LIKE 'foo')
and `item_type` = 'type1'
翻译成雄辩的。我想出了以下声明:
$items = Item::where('item_type', '=', 'type1')
->orWhere('item_name','LIKE','%'.$q.'%')
->orWhere('item_description','LIKE','%'.$q.'%')
->sortable(['id' => 'desc'])
->paginate(10);
在上面的 sn-p 中,$q 将是 foo(这是一个搜索查询)。
问题在于,这并不能完全返回我想要的,因为它还返回属于另一个 item_type 而不是我的示例中的 type1 的项目。
如何在 Eloquent 查询中翻译上述 SQL 查询,使其仅返回包含 foo 且类型为 Type1 的项目?
【问题讨论】:
标签: php laravel eloquent laravel-query-builder