Trying to show the current signed in user's profile. What am i doing wrong.This is the function on the controller. I'm using Laravel 9
public function show(User $user)
{
return view('users.index', with('user', $user));
}
This is the routes
Route::resource('users', UsersController::class)->middleware('auth');
And my generic layout page
<x-dropdown-item href="/users/{{ auth()->user()->username }}" >Account</x-dropdown-item>
When i click the link i get user not found.
CodePudding user response:
You're utilising route model binding which unless configured otherwise, requires you to provide a route with a model id
. You're providing it with a username
, so Laravel is throwing a 404
because it can't locate the relevant record in the database.
If you replace username
with id
, the binding should work.
<x-dropdown-item href="/users/{{ auth()->user()->id }}">
Account
</x-dropdown-item>
CodePudding user response:
The code is fine. Are you sure you have a route with username, resource routes are using id.