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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners