【发布时间】:2015-05-19 23:02:43
【问题描述】:
基本上,我希望能够检索用户并急切地加载电子邮件地址,然后使用 where 子句限制我引入的用户。
$query = User::with('emails')->whereIn ('user_id', $user_ids);
$query->where('emails.email_address', 'LIKE', "%example%");
$usersWithEmails = $query->get();
这行得通:
$query->where('first_name', 'LIKE', "%test%");
这让我相信 where 子句仅适用于基本用户对象,但我不想让用户与该电子邮件不匹配。我知道我可以用几个查询来做到这一点,但这是用于 UI 过滤器,它们可以过滤许多子表,所以这样会更好)。
我该怎么做?
【问题讨论】:
标签: php laravel eloquent eager-loading