【发布时间】:2018-12-18 08:31:05
【问题描述】:
查看API for Builder 似乎查询的所有部分都保存在$joins, $wheres, $groups 等属性中。
我还看到这些属性是公开的。
我的用例是例如范围,比方说(纯虚构)
class User extends Model
{
public function scopeIsSmart($query)
{
return $query->join('tests', 'users.id', '=', 'tests.user')
->where('tests.score', '>', 130);
}
public function scopeIsMathGuy($query)
{
return $query->join('tests', 'users.id', '=', 'tests.user')
->where('tests.type', '=', 'math');
}
}
如果我现在写
User::query()->isSmart()->isMathGuy()->get();
我加入同一个表 2 次会出错。什么是使连接数组独一无二的好方法? (没有重复的连接)
【问题讨论】:
标签: laravel eloquent query-builder