The variable in the method must match the variable in the route. You used "{user}" in the route, so you need to use $user in the method.
Also, you're using route model binding, which means it will retrieve the user, so $user will be the user with the id that you passed in the route, like /profile/5. It is also doing findOrFail behind the scenes when using route model binding, so the equivalent of what you were trying to do would just be
public function user(User $user)
{
dump($user);
}
also use dump(), it's a lot better than var_dump() as it formats everything nicely.
@Cronix I as your advice, I have do like below. I have pass user id manually. I need this id get from currant login user. Because, This is a user profile. Can you help me to do this.
@Cronix
Ok. But my question is how can I redirect to this profile page. Now I pass Id mannually in findOrFail() method like this. $user = User::findOrFail(7). How Can i replace this 7 to current login user id
You most likely don't need to. Let's first clarify something... Should a user only be able to see their own profile, or should a user be able to visit anybodies profile? That will clarify what needs to be done here.
If you're getting null then you are no longer authenticated.
auth()->user()will return the authenticated user, or null if there is no authenticated user. This route should be inside the auth middleware group also.
@tykus not using the auth middleware shouldn't prevent you from viewing the current logged in user though, only prevent them from accessing the route if they aren't authenticated.
I never ever said it was a requirement @Cronix - if you thought about it for a minute, why would you have a profile route that is accessible to a non-authenticated user.