简体   繁体   中英

Laravel 5.0 Model events

A bit confused about model events behaving when using SoftDelete trait. Which event will be fired when object will be deleted? forceDeleted?

A quick glance into laravel/framework/src/Illuminate/Database/Eloquent/SoftDeletes.php shows that SoftDeletes adds two new model events: 'restoring' and 'restored'.

Therefore, you have to listen for the standard events: 'deleting' and 'deleted'. There is no a special 'soft-deleting' kind of event. Also, there are no force deletion events, either.

I've figured out how to implement this feature. There are forceDeleting property in SoftDeletes trait. Which indicates are model deleting soft or hard at the moment. So I need only check this property in my event handler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM