Answer the question
In order to leave comments, you need to log in
How to reduce the number of requests when displaying thumbnails in laravel-medialibrary?
Hey! I use spatie/laravel-medialibrary to load and modify images.
I like this package, but I ran into a little performance problem.
I'm under the impression that for each rendered media image, an additional DB query is executed, querying all the columns from the parent model element.
when outputting, I use
TeamsController.php
$items = Team::latest()->with("media")->limit(10)->get();
@foreach ($items as $item)
<img src="{{ $item->getFirstMediaURL('default', 'thumb') }}" />
@endforeach
Answer the question
In order to leave comments, you need to log in
You obviously don't show us everything. I suppose that somewhere there is foreach($teams as $team), inside which foreach($team->media as $media), and from the media you do $media->team, which cause requests.
Throw off the entire code - the entire template, the controller, as well as the getFirstMediaURL method.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question