-
app/Traits/Sluggable.php
Open in GitHubuse Illuminate\Support\Str; trait Sluggable { public function getRouteKeyName() { return 'slug'; } public static function bootSluggable() { static::created(function ($model) { if (!$model->slug) { $model->slug = Str::slug($model->id . ' ' . $model->title); $model->save(); } }); } }
-
app/Models/Project.php
Open in GitHubuse App\Traits\Sluggable; use Illuminate\Database\Eloquent\Model; class Project extends Model { use Sluggable; // }