enforceOrderBy

This commit is contained in:
邓皓元 2019-01-03 15:50:47 +08:00
parent 1fe0249fac
commit 7f47508627

View File

@ -619,6 +619,20 @@ abstract class Repository implements RepositoryInterface, CacheableInterface, Cr
return $this->sync($id, $relation, $attributes, false);
}
/**
* Add a generic "order by" clause if the query doesn't already have one.
*
* @return void
*/
public function enforceOrderBy()
{
if ($this->model instanceof EloquentBuilder) {
if (empty($this->model->getQuery()->orders) && empty($this->model->getQuery()->unionOrders)) {
$this->orderBy($this->getModel()->getQualifiedKeyName(), 'asc');
}
}
}
/**
* 返回空值
*