Such a call displays all fields from the combined tables.

$model = Model::with('table1', 'table2') ->whereHas('table1',function($t)use($fackt){ $t->where('name','LIKE','%'.$fackt.'%'); }) ->get() 

On large tables, the output of all fields is not the fastest solution, how to display only the fields I need? Tried to use this type of request, but it does not work correctly.

  $model = Model::select('col1', 'col2')->with('table1', 'table2') ->whereHas('table1',function($t)use($fackt){ $t->where('name','LIKE','%'.$fackt.'%'); }) ->get() 

    1 answer 1

     $model = Model::select(['col1', 'col2'])->with('table1', 'table2') ->whereHas('table1',function($t)use($fackt){ $t->select(['id', 'column1', 'column2'])->where('name','LIKE','%'.$fackt.'%'); }) ->get() 

    Just need to choose more fields, like, according to which laravel links your models