So I have a query that I only want to get specific columns in a relation but is not working. I'm using Laravel 5.2 by the way. Here's what I have:
$job = Job::query()->whereId($job_id)
->with([
'jobType' => function (Relation $query) {
$query->select(['name']);
},
])
->first();
If I do that, the jobType relationship returns null
as seen below:
And if I'll remove the $query->select(['name']);
, it has the data from job_type
table. How can I just successfully get specific column from a table?