Answer the question
In order to leave comments, you need to log in
How to delete a file in spatie/laravel-medialibrary?
I get a list of files associated with the model:
@if($share->hasMedia('shares'))
<div class="form-group">
<label>Загруженные изображения</label>
@foreach($share->getMedia('shares') as $media)
<div class="card" style="width: 10rem;">
<img class="card-img-top" src="{{$media->getUrl()}}">
<a class="btn btn-block btn-danger rounded-0"
href="{{route('delete.media',['id'=> $media->id])}}">удалить</a>
</div>
@endforeach
</div>
@endif
class mediaDeleteController extends Controller
{
public function __invoke(Request $request)
{
Media::whereIn('id', [$request->id])->delete();
return back();
}
}
Answer the question
In order to leave comments, you need to log in
I think it is necessary to delete through the model, and not through the query builder. That is like this:
Media::findOrFail($request->id)->delete();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question