赶知识网

给laravel的model增加create或update事件监听

php/mysql/apache 2019-05-17发布 3595次点击

给laravel的model增加create或update事件监听
Laravel: how to create a function After or Before save|update 

class User extends Model 
{


    public static function boot()
    {
        parent::boot();


        self::creating(function($model){
            // ... code here
        });


        self::created(function($model){
            // ... code here
        });


        self::updating(function($model){
            // ... code here
        });


        self::updated(function($model){
            // ... code here
        });


        self::deleting(function($model){
            // ... code here
        });


        self::deleted(function($model){
            // ... code here
        });
    }


}




Top10

沪ICP备09053415号 © 赶知识网