src/HasMedia/HasMediaTrait.php
public function deleteMedia($mediaId)
    {
        if ($mediaId instanceof Media) {
            $mediaId = $mediaId->id;
        }

        $media = $this->media->find($mediaId);

        if (! $media) {
            throw MediaCannotBeDeleted::doesNotBelongToModel($mediaId, $this);
        }

        $media->delete();
    }
public function deleteMedia($mediaId)
    {
        if ($mediaId instanceof Media) {
            $mediaId = $mediaId->id;
        }

        $media = $this->media->find($mediaId);

        if (! $media) {
            throw MediaCannotBeDeleted::doesNotBelongToModel($mediaId, $this);
        }

        $media->delete();
    }
public function deleteMedia ( $ mediaId ) { if ( $ mediaId instanceof Media ) { $ mediaId = $ mediaId -> id ; } $ media = $ this -> media -> find ( $ mediaId ) ; if ( ! $ media ) { throw MediaCannotBeDeleted :: doesNotBelongToModel ( $ mediaId , $ this ) ; } $ media -> delete ( ) ; }
Delete the associated media with the given id.
You may also pass a media object.

@param int|\Spatie\MediaLibrary\Models\Media $mediaId

@throws \Spatie\MediaLibrary\Exceptions\MediaCannotBeDeleted
Delete the associated media with the given id . You may also pass a media object .