Laravel 5.6 Eager Loading specific column returns nothing
I ran into this problem so i had to write my query this way. You will need to retrieve the ID of the foreign Key unless you get a null
value from the relationship
Transaction::with([
'client' => function($query){
$query->select('id', 'first_name');
}
])->get();
You always need foreign key/primary key, involved in the relation, to be selected. fetch product_id too in eager load and it will work
Product::with('formats:id,upc,product_id')->get();