src/Database/Models/Traits/Sortable.php
/**
     * Adds position to model on creating event.
     */
Adds position to model on creating event.
Adds position to model on creating event .
public static function bootSortable()
    {
        static::addGlobalScope('position', function (Builder $builder) {
            $builder->orderBy(static::getSortableField());
        });
        static::saving(
            function ($model) {
                $sortableField = static::getSortableField();
                $query = static::applySortableGroup(static::on(), $model);
                if ($model->$sortableField === null) {
                    $model->setAttribute($sortableField, $query->max($sortableField) + 1);
                }
            }
        );
        static::deleting(
            function ($model) {
                $model->next()->decrement(static::getSortableField());
            }
        );
    }
public static function bootSortable ( ) { static :: addGlobalScope ( 'position' , function ( Builder $ builder ) { $ builder -> orderBy ( static :: getSortableField ( ) ) ; } ) ; static :: saving ( function ( $ model ) { $ sortableField = static :: getSortableField ( ) ; $ query = static :: applySortableGroup ( static :: on ( ) , $ model ) ; if ( $ model -> $ sortableField === null ) { $ model -> setAttribute ( $ sortableField , $ query -> max ( $ sortableField ) + 1 ) ; } } ) ; static :: deleting ( function ( $ model ) { $ model -> next ( ) -> decrement ( static :: getSortableField ( ) ) ; } ) ; }
Adds position to model on creating event.
Adds position to model on creating event .
/* @var Model $model */ // only automatically calculate next position with max+1 when a position has not been set already