Model A, has BelongsTo with Model B. Model B has BelogsTo wit Model C
So, I need to make a query and i need to get * from Model A, 2 columns from Model B and other 2 columns from Model C
ModelA::query()
->with([
'relationModelB' => function ($query) {
$query->select('id', 'column');
},
'relationModelB.relationModelC' => function ($query) {
$query->select('id', 'column');
}
])
->where('id', $id)
->first();
This return all from A, 2 columns from B, but C returns null.
If, I try this query, it returns well, alls columns from 3 models.
ModelA::query()
->with(['relationModelB', 'relationModelB'])
->where('id', $id)
->first();
What is missing in the first query, to get specific columns from the relation of the relation?