protected static function bootSlugUniqueModels()
    {
        // on model's creating and updating event
        foreach (['creating', 'updating'] as $event) {
            static::$event(function ($model) use ($event) {
                // if custom build slug from column not set
                if (!property_exists($model, 'buildSlugFrom')) {
                    $model->setSlugAttribute($model->title);
                }
                else { // use specified column
                    $column = $model->buildSlugFrom;
                    $model->setSlugAttribute($model->{$column});
                }
            });
        }
    }
protected static function bootSlugUniqueModels()
    {
        // on model's creating and updating event
        foreach (['creating', 'updating'] as $event) {
            static::$event(function ($model) use ($event) {
                // if custom build slug from column not set
                if (!property_exists($model, 'buildSlugFrom')) {
                    $model->setSlugAttribute($model->title);
                }
                else { // use specified column
                    $column = $model->buildSlugFrom;
                    $model->setSlugAttribute($model->{$column});
                }
            });
        }
    }
protected static function bootSlugUniqueModels ( ) { // on model's creating and updating event foreach ( [ 'creating' , 'updating' ] as $ event ) { static :: $ event ( function ( $ model ) use ( $ event ) { // if custom build slug from column not set if ( ! property_exists ( $ model , 'buildSlugFrom' ) ) { $ model -> setSlugAttribute ( $ model -> title ) ; } else { // use specified column $ column = $ model -> buildSlugFrom ; $ model -> setSlugAttribute ( $ model -> { $ column } ) ; } } ) ; } }
On create and update, set the slug

@return void
On create and update set the slug