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

kieranheadley's avatar

Class App\Http\Controllers\App\Http\Controllers\*** does not exist

I have created a new project (having created many before) working through different functionality and have come across this issue;

ReflectionException in Route.php line 280: Class App\Http\Controllers\UserController does not exist

Now the UserController does exist in App\Http\Controllers so I am unsure as to what is causing this?

UserController

<?php

namespace App\Http\Controllers;

use App\Http\Requests;
use App\User;
use App\UserTypes;

use Auth;
use Hashids;
use Redirect;
use Request;
use Hash;

class UserController extends Controller
{
    public function index(){
        $users = User::get();
        return view('users.index', compact('users'));
    }

    public function getAdd(){
        $user_type = UserTypes::pluck('user_type', 'id');
        return view('users.add', compact('user_type'));
    }

    public function postAdd(){
        $input = Request::all();
        $password = str_random(8);
        $user = User::create(
            'email' => $input['email'],
            'password' => Hash::make($password),
            'first_name' => $input['first_name'],
            'surname' => $input['surname'],
            'phone_number' => $input['phone_number'],
            'user_type' => $input['user_type'],
        );

        return Redirect::action('UserController@index');
    }

    public function getEdit($id){

    }

    public function postEdit($id){

    }

    public function delete($id){
        User::find(current(Hashids::decode($id)))->delete();
        return Redirect::action('UserController@index');
    }
}

Routes

<?php
Route::get('/', 'PagesController@getLogin');
Route::post('/', 'PagesController@postLogin');
Route::get('/logout', 'PagesController@logout');
Route::get('/unauthenticated', 'PagesController@unauthenticated');
Route::get('/recover-password', 'PagesController@recoverPW');
Route::post('/recover-password', 'PagesController@postRecoverPW');

Route::group(['middleware' => 'auth'], function(){
    Route::get('/route/selector', 'PagesController@selectRoute');

    // Admin Only //
    Route::group(['middleware' => 'isAdmin'], function(){
        Route::get('/admin', 'AdminController@index');
        
        Route::get('/users', 'UserController@index');
        Route::get('/user/add', 'UserController@getAdd');
        Route::post('/user/add', 'UserController@postAdd');
        Route::get('/user/edit/{id}', 'UserController@getEdit');
        Route::post('/user/edit/{id}', 'UserController@postEdit');
        Route::get('/user/delete/{id}', 'UserController@delete');
    });
});

User

<?php

namespace App;

use Auth;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'first_name', 'surname', 'email', 'password', 'phone_number', 'usertype', 'active_status'
    ];

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


    public function isAdmin(){
        if(Auth::user()->user_type == 1){
            return true;
        }else{
            return false;
        }    
    }
}

It seems to show after the following code is added;

$user = User::create(
            'email' => $input['email'],
            'password' => Hash::make($password),
            'first_name' => $input['first_name'],
            'surname' => $input['surname'],
            'phone_number' => $input['phone_number'],
            'user_type' => $input['user_type'],
        );

I hope that someone can help.

0 likes
10 replies
SaeedPrez's avatar

@kieranheadley did you have this problem from start or when did it appear?

Also try..

composer dump-autoload
php artisan optimize
SaeedPrez's avatar

If that doesn't work try rename the file to something like UserController2.php and then php artisan make:controller UserController and see if the error message changes.. if it does, you can copy your methods over to the new controller file.

kieranheadley's avatar

thanks @SaeedPrez it started when I added;

$user = User::create(
            'email' => $input['email'],
            'password' => Hash::make($password),
            'first_name' => $input['first_name'],
            'surname' => $input['surname'],
            'phone_number' => $input['phone_number'],
            'user_type' => $input['user_type'],
        );

I have changed this to;

$user = new User;
        $user->email = $input['email'];
        $user->password = Hash::make($password);
        $user->first_name = $input['first_name'];
        $user->surname = $input['surname'];
        $user->phone_number = $input['phone_number'];
        $user->user_type = $input['user_type'];
        $user->save();

and it works however that is just bypassing the issue. I will give the fixes a try.

kieranheadley's avatar

@SaeedPrez Have tried the above and nothing worked, will continue to look but use my alternative solution for now. Will test as I go along with the ::Create() method in a different controller and see if I get the same issue.

pmall's avatar
$user = User::create(
            'email' => $input['email'],
            'password' => Hash::make($password),
            'first_name' => $input['first_name'],
            'surname' => $input['surname'],
            'phone_number' => $input['phone_number'],
            'user_type' => $input['user_type'],
        );

The array brackets are missing

erikharden's avatar
Level 1

You are probably actually getting 2 errors, only that the last one gets shown on the top of the page, and that error is that the controller does not exist. The reason why you are seeing that error is because the Model::create() method expects an array of attributes, whilst you are calling it with separate arguments instead.

Try to do:

$user = User::create([
            'email' => $input['email'],
            'password' => Hash::make($password),
            'first_name' => $input['first_name'],
            'surname' => $input['surname'],
            'phone_number' => $input['phone_number'],
            'user_type' => $input['user_type'],
        ]);

Instead and tell us if the errors disappear.

macMillan's avatar

arget class [App\Http\Controllers\DashboardController] does not exist.

Please or to participate in this conversation.