#select for parent and child

7 messages · Page 1 of 1 (latest)

wraith rain
#

morning,
i have little problem about select for parend and related obiect, below u can see little cutted fragment of code

$workplaces = Workplace::select('id');
$workplaces = $workplaces->with(['users' => function($query) {
  return $query->select('id', 'name'');
}]);
$workplaces = $workplaces->get();

the problem is when i set select for workplace, user is always empty, i tried also add to select something like users.id, but then i got errors, its possible to do something like this using with? i dont want joins here (in code, its about functions, i know joins are hidden here) because it has to be dynamic and with is more clear in code

#

select for parent and child

ocean cypress
wraith rain
#
$workplaces = Workplace::select($request->columns);
$workplaces = $workplaces->with('user:id');
$workplaces = $workplaces->get();

this code also returning user null, i need limit workplace fields also, this is why i have first select

trail moth
#

You have to include the foreign key from users.

quaint scarab