Answer the question
In order to leave comments, you need to log in
How to optimize the display of all elements on the page?
Hello! How can I optimize the output of all elements on the page? Let's say there are more than 10,000 of them, then the page loads more than 2-3 seconds.
$cat = Category::with('translations.team')->where('slug', '=', $slug)->firstOrFail();
$translation = $cat->translations;
$translations = CollectionHelper::paginate($translation, $translation->count(), 15);
return view('translation.index', compact('cat'))->with([
'category' => $cat,
'translations' => $translations,
]);
Answer the question
In order to leave comments, you need to log in
$category = Category::whereSlug($slug)
->firstOrFail();
$translations = $category->translations()
->with('team')
->paginate(15);
return view('translation.index', compact('category', 'translations'));
Why are you fetching all the data if you then paginate and display only 15 records?
Why not get only these 15 records from the database?
And why not do it not through with (), but with a regular request to the desired model, and then it already checks that there is a category with the desired slug.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question