Проблема заключается в том, чтобы добавить порядок по заказу от SQL. class = "lang-php prettyprint-override">
Код: Выделить всё
trait Prioritiable
{
protected static function bootPrioritiable(): void
{
static::retrieved(function ($model) {
$model->addGlobalScope(OrderByPriorityScope::class);
});
}
}
. /> или сделать что-то подобное < /p>
Код: Выделить всё
public function apply(Builder $builder, Model $model)
{
$query = $builder->getQuery();
// Apply only for SELECT queries that aren't aggregates
if ($query->columns !== null && $query->aggregate === null) {
$builder->orderBy('priority');
}
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... in-laravel