Reputation:
I want to edit users so I added this as link:
<a href="{{ route('users.edit', $user->name) }}" class="on-default edit-row">Edit</a>
And at the Controller:
public function edit(User $user)
{
$roles = Role::where('slug', '!=', 'super-admin')->get();
return view('admin.users.edit', compact('roles', 'user'));
}
So as you can see I have called the $user
from User
Model but now the problem is, it says:
404 | NOT FOUND
However if I remove User $user
to $id
, it will be working fine !
So what is going wrong here ? How can I properly use Route Model Binding here ?
I would really appreciate any idea or suggestion from you guys...
Thanks in advance.
Upvotes: 0
Views: 70
Reputation: 1843
You have to pass the user's id instead of the users name to your route.
<a href="{{ route('users.edit', $user->id) }}" class="on-default edit-row">Edit</a>
Otherwise, if you want to use the user's name you have two options
public function getRouteKeyName()
{
return 'name';
}
Route::get('/users/{user:name}/edit', function (User $user) {
// ...
});
Upvotes: 1