I am trying to eager load a model in laravel but only return certain columns. I do not want the whole eager loaded table being presented.
public function car
In your controller you should be doing something like
App\Car::with('owner:id,name,email')->get();
Supposing that you have two models defined like below
belongsTo('App\Owner', 'owner_id');
}
}
and
hasMany('App\Car', 'owner_id');
}
}
and you have two tables something like:
owners: id | name | email | phone | other_columns...
and
cars: id | owner_id | make | color | other_columns...
Credits go to the docs: eloquent-relationships#eager-loading scroll to Eager Loading Specific Columns