Did you know that 1 in 4 visitors would abandon a website if it takes more than 4 seconds to load? While multiple factors can slow down a website, one common factor is inefficient database queries.

Our controller would look something like this: public function index() { return view('products', [ 'products' => Products::query()->paginate()]); }

To use eager loading, you call the with method in your query public function index() { return view('products', [ 'products' => Products::query() ->select(['id', 'title', 'slug', 'thumbnail']) ->with('brand') ->paginate()]); }

We can do this by adding a.category to the load method call: public function show(Category $category) { $category->load('products.category'); // eager load the products return view('categories.show', ['category' => $category]); }
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners