Using model->delete() does not seem to invoke a call to delete all attached media. #3767
Open
Description
Calling model->delete() does not clear images in storage. Have to call clearMediaCollection() before calling delete() on model.
class Item extends Model implements HasMedia
{
use HasFactory, InteractsWithMedia, HasSlug;
public function registerMediaConversions(?Media $media = null): void
{
$this->addMediaConversion('thumbnail')
->width(368)
->height(232)
->sharpen(10)
->nonQueued();
}
}
$item = Item::factory()->create([]);
$image = fake()->image(dir: storage_path('app/public/items'), width: 1024, height: 1024, category: 'flowers');
$item->addMedia($image)->preservingOriginal()->toMediaCollection();
Not working:
$item->delete();
public> php artisan media-library:clean
Output: Orphaned media directory `1` has been removed
Working:
$item->clearMediaCollection();
$item->delete();
public> php artisan media-library:clean
Output: All done!
Metadata
Assignees
Labels
No labels