Handling Events After Every Model Save in Laravel

Stefan Bogdanescu
Founder & Senior Architect · 4 July 2026

When working with models in a Laravel application, one of the most powerful features is the ability to attach events that fire after certain actions, such as saving or updating a model. This capability allows us to extend the core behavior of our modules by adding additional logic.

Understanding Laravel Model Events

In Laravel’s architecture, developers can attach listeners to specific model events using the boot method in the model class. The most common events are:

  • creating: Fires before a new record is created.
  • created: Fires after a new record has been created and saved.
  • saving: Fires before a record is updated or inserted.
  • saved: Fires after a record has been updated or inserted.
  • deleting: Fires before a record is deleted from the database.
  • deleted: Fires after a record has been removed from the database.

Declaring and Attaching Events

Let’s assume we have a simple User model. To attach an event listener, we first need to declare it inside the model:

class User extends Model
{
    protected $dispatchesEvents = [
        'saved' => SavedEvent::class,
    ];
}

In this example, every time a User model is saved (either created or updated), Laravel will dispatch the SavedEvent. The event class (SavedEvent) must implement the Illuminate\Queue\SerializesModels trait and return an array of data when its handle method is called.

Registering Event Listeners

Once we have declared our events, the next step is to register listeners that handle these events. Laravel uses a central listener registry for this purpose. You can specify your listeners in the EventServiceProvider:

class EventServiceProvider extends ServiceProvider
{
    protected $listen = [
        'App\Events\Saved' => [
            'App\Listeners\SendNotification',
            'App\Listeners\LogActivity',
        ],
    ];
}

In this example, when a User is saved and the SavedEvent is dispatched, both the SendNotification listener (which might send an email to the user) and the LogActivity listener (which might log the activity in your application’s database) will be triggered.

Logging All Model Save Events

If you want to log all save events across your entire application (not just for one specific model), you can create a global event listener. Here’s how:

  1. Create an event listener class, e.g., LogModelSaveEvent:
class LogModelSaveEvent
{
    public function handle($event)
    {
        // Log the event data to your application's log file or database.
        \Log::info("{$event->model} model saved");
    }
}
  1. Register this listener in the EventServiceProvider. In addition to any specific listeners, you can add a global listener:
protected $listen = [
    // Specific event listeners...

    'App\Events\ModelSaved' => [
        'App\Listeners\LogModelSaveEvent',
    ],
];
  1. Create an abstract model class that extends the base Model and declares a saved event for all models that extend it:
abstract class Model extends \Illuminate\Database\Eloquent\Model
{
    protected $dispatchesEvents = [
        'saved' => ModelSaved::class,
    ];
}
  1. Make your models extend this abstract model instead of the base Model.

Now, whenever any model in your application is saved (created or updated), the LogModelSaveEvent listener will be triggered, logging the event to your application’s log file.

Conclusion

Laravel provides robust support for handling events after every model save through its built-in event system. By declaring and attaching events in your models and registering listeners in the EventServiceProvider, you can easily extend the behavior of your modules without modifying their core logic. This approach promotes clean, reusable code and allows you to maintain a clear separation between your business logic and the events that trigger it.

Remember to always follow best practices when working with events to ensure optimal performance and maintainability in your Laravel applications. If you need further guidance on building scalable and efficient Laravel solutions, be sure to check out our Laravel Company blog for more insights from senior developers.

Happy coding!

Our network