Is it possible to temporarily disable event in Laravel?

前端 未结 7 1595
轮回少年
轮回少年 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:41

    In laravel 8.x :

    Saving A Single Model Without Events

    Sometimes you may wish to "save" a given model without raising any events. You may accomplish this using the saveQuietly method:

    $user = User::findOrFail(1);
    
    $user->name = 'Victoria Faith';
    
    $user->saveQuietly();
    

    See Laravel docs

提交回复
热议问题