Is it possible to temporarily disable event in Laravel?

前端 未结 7 1624
轮回少年
轮回少年 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 11:03

    To answer the question for anyone who ends up here looking for the solution, you can disable model listeners on an instance with the unsetEventDispatcher() method:

    $flight = App\Flight::create(['name' => 'Flight 10']);
    $flight->unsetEventDispatcher();
    $flight->save(); // Listeners won't be triggered
    

提交回复
热议问题