Get column from grandchild table in laravel

50 Views Asked by At

I have 3 tables Table A, Table B and Table C

Table 1 has many Table B and Table B has many Table C

I am using this query

TableA::where(whereclause)->with(TableB.TableC)

Now i want to select some column from table c in controller is there any way to get column from table c like this

TableA::where(whereclause)->with(TableB:col1,col2)
1

There are 1 best solutions below

1
On
TableA::where(whereclause)->with(['TableB' => function($query) {
    $query->select('id','username');
}])->get();