错误edit()必须是App \ User的实例,没有给出

i created a UserController.php

use App\User;
//

class UsersController extends Controller
{
//

    public function edit($id, User $user){
      $user = $user->find($id);
      return view('admin.user.edit' , compact('user'));
    }

 //


}

And edit views

but when i want to access to this url

url('/users/'. $user->id .'edit')

i got this error

Error edit() must be an instance of App\User, none given

!?

Make sure your route is like:

Route::get(/users/{id}/edit', 'UsersController@edit');

Then use it as:

url('/users/'. $user->id .'/edit');

or

url("/users/{$user->id}/edit");

And then your controller should be as:

public function edit($id) {
  $user = User::find($id);
  return view('admin.user.edit' , compact('user'));
}

The error says that the edit() function expects $user_id and User instance but you're only providing $user_id. If that's the case your code should look like this:

public function edit($id){
      $user = User::find($id);
      return view('admin.user.edit' , compact('user'));
}