我正在尝试在与其相关的某些标签上过滤我的模型。我目前有这个代码:
$letters = \App\Letter::with(['tags' => function($query) {
foreach(\Cookie::get('tags') as $tag => $name) {
$query->where('tags.id', $tag);
}
}])->orderBy('created_at', 'desc')->where('service','send')->where('mailbox_id', '=', Auth::user()->activeMailboxId)->paginate(8);
我想获取所有带有关系标签的字母,这样我就可以遍历 cookie 并动态添加 where 语句。但是,它不仅返回带有 cookie 数组标签的字母,而是返回附加到我的帐户的所有字母,有人知道如何做到这一点吗?
谢谢!