Answer the question
In order to leave comments, you need to log in
How to get user name from belongsTo collection?
In the controller
public function getUserPhotos($id)
{
$photos = Photo::with('user')->where('user_id', $id)->get();
$user = User::find($id);
return view('user.userphotos', [
'photos' => $photos,
'user' => $user
]);
}
Answer the question
In order to leave comments, you need to log in
Well, like this:
$user = User::with('photos')->where('id', $id)->first();
return \view('....', ['photos' => $user->photos, 'user' => $user]);
$photos is an array, it does not have a name property, only the elements of this array have this property.
So the only way is with a separate receipt of the user, but you can remove the user selection for the photo.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question