Is it possible to temporarily disable event in Laravel?

前端 未结 7 1603
轮回少年
轮回少年 2020-12-16 10:21

I have the following code in \'saved\' model event:

Session::flash(\'info\', \'Data has been saved.\')` 

so everytime the model is saved I

7条回答
  •  借酒劲吻你
    2020-12-16 10:52

    In laravel 7.x you can do that as easy as

    use App\User;
    
    $user = User::withoutEvents(function () use () {
        User::findOrFail(1)->delete();
    
        return User::find(2);
    });
    

    See more in Laravel 7.x Muting Events documentation

提交回复
热议问题