Eager load relationship

If you use Route Model Binding and think you can't use Eager Loading for relationships, think again.

So you use Route Model Binding

1public function show(Product $product) {
2 //
3}

But you have a belongsTo relationship, and cannot use $product->with('category') eager loading?

You actually can! Load the relationship with ->load()

1public function show(Product $product) {
2 $product->load('category');
3 //
4}

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord