Specify Columns While Eager Loading

Written by Luka Peharda

While eager loading eloquent relationships using with method you can specify (“select”) which columns you want to have returned:

User::where(...)->with('business:id,name')->get()

Mind you, id is required in order for relationship matching to work.

This is available in Laravel since version 5.3.

Source

• • •

If you like this article consider tweeting or check out my other TILs.