How do you add a global scope to help sorting records by default in Laravel?

protected static function boot()
{
    parent::boot();

    static::addGlobalScope('order', function (Builder $builder) {
        $builder->orderBy('first_name');
    });
}

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top