View Not Found While Trying To Use Route Model Binding

  laravel, laravel-8, php

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.

Source: Ask PHP

LEAVE A COMMENT