I have two tables User
and Car
. One user may have a car.
I have a relation set like this:
public function car()
{
return $this->hasOne('App\Car');
}
I want to fetch the users with a car, but only select the name
of the user and the color
of the car.
If I try
App\User::with('car:color')->select('name')->first()->toArray();
then I do not get the car color. That is the result:
array:1 [▼
0 => array:2 [▼
"name" => "Max Mustermann"
"car" => []
]
]
Is it possible to only get the name of the user and the color of the car?