laravel model callbacks after save, before save, etc

后端 未结 7 2026
傲寒
傲寒 2020-11-30 09:34

Are there callbacks in Laravel like:

afterSave()
beforeSave()
etc

I searched but found nothing. If there are no such things - what is best

7条回答
  •  有刺的猬
    2020-11-30 10:26

    Adding in an example for Laravel 4:

    class Page extends Eloquent {
    
        public static function boot()
        {
            parent::boot();
    
            static::creating(function($page)
            {
                // do stuff
            });
    
            static::updating(function($page)
            {
                // do stuff
            });
        }
    
    }
    

提交回复
热议问题