-
app/Observers/ArticleObserver.php
Open in GitHubuse App\Models\Article; use Illuminate\Support\Str; use Ramsey\Uuid\Uuid; class ArticleObserver { public function saving(Article $article) { $article->id = Uuid::uuid4(); $article->slug = Str::slug($article->title); } }
-
app/Providers/AppServiceProvider.php
Open in GitHubuse App\Observers\ArticleObserver; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { /// public function boot() { Article::observe(ArticleObserver::class); // } // }