Is it possible to temporarily disable event in Laravel?

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

    You shouldnt be mixing session flashing with model events - it is not the responsibility of the model to notify the session when something happens.

    It would be better for your controller to call the session flash when it saves the model.

    This way you have control over when to actually display the message - thus fixing your problem.

提交回复
热议问题