优化范围查询

This commit is contained in:
JaguarJack 2020-06-22 15:19:50 +08:00
parent d873ba10f9
commit f18766c20a

View File

@ -23,7 +23,7 @@ trait ScopeTrait
*/ */
public function scopeCreator($query) public function scopeCreator($query)
{ {
if (in_array('creator_id', $this->field)) { if (property_exists($this, 'field') && in_array('creator_id', $this->field)) {
return $query->addSelectSub(function () { return $query->addSelectSub(function () {
$user = app(Users::class); $user = app(Users::class);
return $user->whereColumn($this->getTable() . '.creator_id', $user->getTable() . '.id') return $user->whereColumn($this->getTable() . '.creator_id', $user->getTable() . '.id')