Laravel-medialibrary: Deleting a model doesn't delete media/file

Created on 23 Feb 2018  路  1Comment  路  Source: spatie/laravel-medialibrary

I've got media models related to records in a videos table. If I delete a record in videos, the model in media doesn't delete.

If I go:
$videos = Video::where('set_id', $request->set_id)->delete();

I'd expect each model in media along with the file to be deleted too.

What am I doing wrong?

Most helpful comment

To determine when to delete files this package hooks into Laravel's model events. Those events won't get fired when mass deleting using the query builder.

To fix this you should delete models one by one:

Video::where('set_id', $request->set_id)->each->delete();

Keep in mind that this will fire off multiple queries.

>All comments

To determine when to delete files this package hooks into Laravel's model events. Those events won't get fired when mass deleting using the query builder.

To fix this you should delete models one by one:

Video::where('set_id', $request->set_id)->each->delete();

Keep in mind that this will fire off multiple queries.

Was this page helpful?
0 / 5 - 0 ratings