huuuk
huuuk

Reputation: 4795

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?

Upvotes: 0

Views: 99

Answers (2)

huuuk
huuuk

Reputation: 4795

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.

Upvotes: 0

Denis Mysenko
Denis Mysenko

Reputation: 6534

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.

Upvotes: 1

Related Questions