laravel model callbacks after save, before save, etc

后端 未结 7 2028
傲寒
傲寒 2020-11-30 09:34

Are there callbacks in Laravel like:

afterSave()
beforeSave()
etc

I searched but found nothing. If there are no such things - what is best

相关标签:
7条回答
  • 2020-11-30 10:30

    If you want control over the model itself, you can override the save function and put your code before or after __parent::save().

    Otherwise, there is an event fired by each Eloquent model before it saves itself.

    There are also two events fired when Eloquent saves a model.

    "eloquent.saving: model_name" or "eloquent.saved: model_name".

    http://laravel.com/docs/events#listening-to-events

    0 讨论(0)
提交回复
热议问题