Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

YuraLons's avatar

Error artisan route:list

When executing a request, the artisan route: the list pops up such an error.

Everything was done according to the installation instructions, but I can not add permissions and users through the admin panel.


  Illuminate\Contracts\Container\BindingResolutionException

 Target class [App\Http\Controllers\UsersController] does not exist.

 at C:\htdocs\www\rpc\vendor\laravel\framework\src\Illuminate\Container\Container.php:807
   803|
   804|         try {
   805|             $reflector = new ReflectionClass($concrete);
   806|         } catch (ReflectionException $e) {
  807|             throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
808|         }
  809|
   810|         // If the type is not instantiable, the developer is attempting to resolve
   811|         // an abstract type such as an Interface or Abstract Class and there is

 1   [internal]:0
     Illuminate\Foundation\Console\RouteListCommand::Illuminate\Foundation\Console\{closure} (Object(Illuminate\Routing\Route))

 2   C:\htdocs\www\rpc\vendor\laravel\framework\src\Illuminate\Container\Container.php:805
     ReflectionException::("Class App\Http\Controllers\UsersController does not exist")
PS C:\htdocs\www\rpc>

UserController.php

<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\User;
use App\Role;
use App\Permission;

class UsersController extends Controller
{
    //

    public function __construct()
    {
        //$this->middleware('role:users');
    }

    // Index Page for Users
    public function index()
    {
        $users = User::paginate(10);
        
        $params = [
            'title' => 'Users Listing',
            'users' => $users,
        ];

        return view('admin.users.users_list')->with($params);
    }

    // Create User Page
    public function create()
    {
        $roles = Role::all();

        $params = [
            'title' => 'Create User',
            'roles' => $roles,
        ];

        return view('admin.users.users_create')->with($params);
    }

    // Store New User
    public function store(Request $request)
    {
        $this->validate($request, [
            'name' => 'required',
            'email' => 'required|unique:users',
            'password' => 'required',
        ]);

        $user = User::create([
            'name' => $request->input('name'),
            'email' => $request->input('email'),
            'password' => bcrypt($request->input('password')),
        ]);

        $role = Role::find($request->input('role_id'));

        $user->attachRole($role);

        return redirect()->route('users.index')->with('success', "The user <strong>$user->name</strong> has successfully been created.");
    }

    // Delete Confirmation Page
    public function show($id)
    {
        try {
            $user = User::findOrFail($id);

            $params = [
                'title' => 'Confirm Delete Record',
                'user' => $user,
            ];

            return view('admin.users.users_delete')->with($params);
        } catch (ModelNotFoundException $ex) {
            if ($ex instanceof ModelNotFoundException) {
                return response()->view('errors.' . '404');
            }
        }
    }

    // Editing User Information Page
    public function edit($id)
    {
        try {
            $user = User::findOrFail($id);

            //$roles = Role::all();
            $roles = Role::with('permissions')->get();
            $permissions = Permission::all();

            $params = [
                'title' => 'Edit User',
                'user' => $user,
                'roles' => $roles,
                'permissions' => $permissions,
            ];

            return view('admin.users.users_edit')->with($params);
        } catch (ModelNotFoundException $ex) {
            if ($ex instanceof ModelNotFoundException) {
                return response()->view('errors.' . '404');
            }
        }
    }

    // Update User Information to DB
    public function update(Request $request, $id)
    {
        try {
            $user = User::findOrFail($id);

            $this->validate($request, [
                'name' => 'required',
                'email' => 'required|email|unique:users,email,' . $id,
            ]);

            $user->name = $request->input('name');
            $user->email = $request->input('email');

            $user->save();

            // Update role of the user
            $roles = $user->roles;

            foreach ($roles as $key => $value) {
                $user->detachRole($value);
            }

            $role = Role::find($request->input('role_id'));

            $user->attachRole($role);

            // Update permission of the user
            //$permission = Permission::find($request->input('permission_id'));
            //$user->attachPermission($permission);

            return redirect()->route('users.index')->with('success', "The user <strong>$user->name</strong> has successfully been updated.");
        } catch (ModelNotFoundException $ex) {
            if ($ex instanceof ModelNotFoundException) {
                return response()->view('errors.' . '404');
            }
        }
    }

    // Remove User from DB with detaching Role
    public function destroy($id)
    {
        try {
            $user = User::findOrFail($id);

            // Detach from Role
            $roles = $user->roles;

            foreach ($roles as $key => $value) {
                $user->detachRole($value);
            }

            $user->delete();

            return redirect()->route('users.index')->with('success', "The user <strong>$user->name</strong> has successfully been archived.");
        } catch (ModelNotFoundException $ex) {
            if ($ex instanceof ModelNotFoundException) {
                return response()->view('errors.' . '404');
            }
        }
    }
}

User.php

<?php

namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laratrust\Traits\LaratrustUserTrait;

class User extends Authenticatable
{
    use LaratrustUserTrait;
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
}
0 likes
9 replies
siangboon's avatar

Target class [App\Http\Controllers\UsersController] does not exist.

possible that your route file (web.php) forgot to group or prefix the "Admin\" for UsersController....

YuraLons's avatar

But I also do not have an admin panel Web.php

Route::group(['middleware' => ['role:administrator']], function () {

    Route::resource('users', 'UsersController');    
    Route::resource('permission', 'PermissionController');    
    Route::resource('roles', 'RolesController'); 
      
});  
YuraLons's avatar

So I figured out the error. Log in to mydomain / admin / users

Facade\Ignition\Exceptions\ViewException
Missing required parameters for [Route: users.edit] [URI: admin/users/{user}/edit]. (View: C:\htdocs\www\rpc\resources\views\admin\users\users_list.blade.php)
http://127.0.0.1:8000/admin/users
siangboon's avatar

i think this "Missing required parameters for [Route: users.edit] " is different error... (better create another thread to avoid confusing others)

the information given in the thread show that your UsersController is not defined in App\Http\Controllers but *App\Http\Controllers\Admin* according to your namespace

namespace App\Http\Controllers\Admin;

hence the error occurred

Target class [App\Http\Controllers\UsersController] does not exist

meant that the system can't find UsersController in App\Http\Controllers folder....

and most likely this error is triggered at your route file

Route::group(['middleware' => ['role:administrator']], function () {

    Route::resource('users', 'UsersController');   
    ...

should be

Route::namespace('Admin')->group(['middleware' => ['role:administrator']], function () {

    Route::resource('users', 'UsersController');  
   ...

or

Route::group(['middleware' => ['role:administrator']], function () {

    Route::resource('users', 'Admin\UsersController');   
    ...
YuraLons's avatar

In files ( UserController.php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\User;
use App\Role;
use App\Permission;

RolesController.php

<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Role;
use App\Permission;
use Illuminate\Support\Facades\DB;

and PermissionController.php

<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\User;
use App\Role;
use App\Permission;
use Illuminate\Support\Facades\DB;

In the Admin folder, I did not change anything other than the models, that is, all the paths

<?php
namespace App\Http\Controllers\Admin

) there are correct namespace, I only changed use App \ Models \ (User, Role, Permission)

Web.php

<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/admin', function () {
    return view('admin.dashboard');
});

Route::get('/', function () {
    return view('home');
});

Route::namespace('Admin')->group(['middleware' => ['role:administrator']], function () {

    Route::resource('users', 'Admin\UsersController');
    Route::resource('roles', 'Admin\RolesController'); 
    Route::resource('permissions', 'Admin\PermissionController');  
});

Route::group(['prefix' => 'admin', 'middleware' => 'auth', 'middleware' => ['role:administrator|superadministrator'], 'namespace' => 'Admin'], function () {
    Route::resource('/users', 'UsersController');
    Route::resource('/permission', 'PermissionController');
    Route::resource('/roles', 'RolesController');
});  
YuraLons's avatar

ErrorException Array to string conversion

YuraLons's avatar

If you go to the page /users /role /permissions, then an error pops up

Facade\Ignition\Exceptions\ViewException
Missing required parameters for [Route: permission.edit] [URI: permission/{permission}/edit]. (View: C:\htdocs\www\rpc\resources\views\admin\permission\perm_list.blade.php)

But if you go to the / users/create page, then everything is fine. The control panel opens

YuraLons's avatar

and more error

Facade\Ignition\Exceptions\ViewException
Undefined variable: n_users (View: C:\htdocs\www\rpc\resources\views\admin\dashboard.blade.php)
http://127.0.0.1:8000/admin
Hide solutions
Possible typo $n_users
Did you mean $errors?
siangboon's avatar

it is better solve a problem at a time, otherwise it's not only very confusing and mess up the problems...

Target class [App\Http\Controllers\UsersController] does not exist.

if the above issue resolved then just simply briefly explain what you did that solved the issue, then close the thread... for other following questions, then just create another new one

This will help and ease others who encountered the same issue to refer back...

Please or to participate in this conversation.