UsersController上的Laravel Parse错误[重复]

This question already has an answer here:

I'm trying to list all users and so have created a UsersController which goes like:

class UsersController extends Controller
{

public function show(User $user)
{
    //
    $users = User::all();

    return view('superadmin.user.index', compact('users'));
}

}

And a Route that goes like:

Route::get('/superadmin/user', 'UsersController', function () {
        if(Auth::user()->role[0]->id != 3) {
            return redirect('/home');
        } else {
            return view('superadmin.user.index');
        }
});

and finally trying to call it with:

@foreach ($users as $user)
  {{ $user->username }}
@endforeach

But I'm getting: Parse error: syntax error, unexpected 'class' (T_CLASS), expecting ',' or ';'

On the class UsersController line, so i at least know its getting that far. Ive read all the parse error questions and followed a few tutorials on listing users but everything seems to hang up here.

Where am I going wrong?

</div>

A previous line to class UsersController did not end with semi colon. It is a syntax error. Find the line and add semi colon ;

You have many issues:

In route you did not write to which method goes and it is not practical to return the view inside the route you can fix it as the following

Route::get('/superadmin/user/{user}', 'UsersController@show');

and in the controller make the operations you want. If you want to check the rule of user you can make middleware and check the rules.