Laravel Observers: React to Model Events
January 16, 2026
•
1 min read
•
17 views
Table of Contents
Centralize model events:
Create Observer
php artisan make:observer UserObserver --model=User
Observer Methods
class UserObserver
{
public function created(User $user)
{
Mail::to($user)->send(new WelcomeMail());
}
public function deleted(User $user)
{
$user->posts()->delete();
}
public function forceDeleted(User $user)
{
Storage::delete($user->avatar);
}
}
Register Observer
public function boot()
{
User::observe(UserObserver::class);
}
Related Posts
Laravel Sanctum API Authentication Complete Guide
Build secure API authentication with Laravel Sanctum for SPAs and mobile apps.
Laravel Rate Limiting: Protect Your Application
Implement rate limiting to protect your Laravel application from abuse.
Laravel Blade Components: Build Reusable UI
Create powerful reusable components with Laravel Blade.
Comments (0)
No comments yet. Be the first to comment!