我有这个疑问:如何使用同一个雄辩查询两次,但使用一个不同的where子句?
User::leftJoin('friends', function ($join) {
$join->on('friends.user_id_1', '=', 'users.id')
->orOn('friends.user_id_2', '=', 'users.id');
})
->where(function ($query) use ($myID) {
// Group orwhere functions so the query builder knows these belong together
$query->where([
'friends.user_id_1' => $myID,
'friends.accepted' => true
])
->orWhere([
'friends.user_id_2' => $myID,
'friends.accepted' => true
]);
})
->where('users.id', '!=', $myID) // Exclude the user with id $myID
->get();
https://stackoverflow.com/a/41832867/5437864
我想两次使用此查询,但使用不同的where子句。是否可以在不复制整个代码的情况下重用此查询?如果是这样,怎么样?
是的,是的。 – nogad
@nogad谢谢,但如何? :) – Z0q
请在您的文章中至少包含部分链接内容,否则链接可能无法与时间匹配,问题将无法理解 – Icarus