laravel model callbacks after save, before save, etc

laravel, php

Solution

Actually, Laravel has real callback before|after save|update|create some model. check this:

https://github.com/laravel/laravel/blob/3.0/laravel/database/eloquent/model.php#L362

the EventListener like saved and saving are the real callbacks

$this->fire_event('saving'); 

$this->fire_event('saved');

how can we work with that? just assign it to this eventListener example:

 \Laravel\Event::listen('eloquent.saving: User', function($user){
  $user->saving();//your event or model function
});

Problem

Are there callbacks in Laravel like: ``` afterSave() beforeSave() etc ``` I searched but found nothing. If there are no such things - what is best way to implement it? Thanks!

Original source

Related problems