Cviebrock\EloquentSluggable\Services\SlugService::slug PHP Méthode

slug() public méthode

Slug the current model.
public slug ( Model $model, boolean $force = false ) : boolean
$model Illuminate\Database\Eloquent\Model
$force boolean
Résultat boolean
    public function slug(Model $model, $force = false)
    {
        $this->setModel($model);
        $attributes = [];
        foreach ($this->model->sluggable() as $attribute => $config) {
            if (is_numeric($attribute)) {
                $attribute = $config;
                $config = $this->getConfiguration();
            } else {
                $config = $this->getConfiguration($config);
            }
            $slug = $this->buildSlug($attribute, $config, $force);
            $this->model->setAttribute($attribute, $slug);
            $attributes[] = $attribute;
        }
        return $this->model->isDirty($attributes);
    }

Usage Example

 /**
  * @param \Illuminate\Database\Eloquent\Model $model
  * @param string $event
  * @return boolean|null
  */
 protected function generateSlug(Model $model, $event)
 {
     // If the "slugging" event returns a value, abort
     if ($this->fireSluggingEvent($model, $event) !== null) {
         return;
     }
     $wasSlugged = $this->slugService->slug($model);
     $this->fireSluggedEvent($model, $wasSlugged);
 }