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

mstnorris's avatar

Class App\Http\Controllers\AuthController does not exist

Update

The upgrade guide on the Laravel homepage doesn't include the correct namespace for the Authentication routes. I've submitted a pull request to update the docs and I'll amend this message when it is corrected.


ReflectionException in Container.php line 736: Class App\Http\Controllers\AuthController does not exist

I'm using the latest dev version of 5.1 and when I hit the /auth/login route I get this error. I have followed the Upgrading To 5.1.0 guide as best as I can and as far as I know I have done everything asked of me.

What else should I do? What other information do you need from me in order to help?

I've run:

composer update

composer dump-autoload -o

php artisan clear-cache

AuthController app/Http/Controllers/Auth

<?php namespace App\Http\Controllers\Auth;

use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Registration & Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users, as well as the
    | authentication of existing users. By default, this controller uses
    | a simple trait to add these behaviors. Why don't you explore it?
    |
    */

    use AuthenticatesAndRegistersUsers;

    protected $redirectTo = '/guestbook';

    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'getLogout']);
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|confirmed|min:6',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }
}

routes.php

// Authentication routes...
get('auth/login', 'AuthController@getLogin');
post('auth/login', 'AuthController@postLogin');
get('auth/logout', 'AuthController@getLogout');

// Registration routes...
get('auth/register', 'AuthController@getRegister');
post('auth/register', 'AuthController@postRegister');
0 likes
12 replies
bestmomo's avatar

Isn't it App\Http\Controllers\Auth\AuthController ? Look in your routes.

1 like
mstnorris's avatar

@bestmomo yes it is, and it is that in the actual file structure but the routes are defined as per the docs. Either I am being incredibly stupid and having a moment or there is something missing in the guide.

I've added routes.php.

mstnorris's avatar

@bestmomo have you any other ideas, I've looked through the code, it is using the latest version and just removed vendor directory completely and re run composer update so everything is up-to-date there.

Anything else you can think of?

mstnorris's avatar

@bestmomo I had just spotted that when you asked as I was checking out another project of mine. I had never noticed that the routes were namespaced like so:

What I had in a different project

get('login', ['as' => 'login_path', 'uses' => 'Auth\AuthController@getLogin']);
get('register', ['as' => 'register_path', 'uses' => 'Auth\AuthController@getRegister']);
get('logout', ['as' => 'logout_path', 'uses' => 'Auth\AuthController@getLogout']);

Route::controllers([
    'auth' => 'Auth\AuthController',
    'password' => 'Auth\PasswordController',
]);

So, in short it looks like the upgrade guide is wrong. I have submitted a pull request.

mstnorris's avatar

I know, I have submitted a pull request, should be merged shortly. I submitted one the other day and it was taken care of within a couple of minutes.

gcpatton's avatar

I ran into this issue also. I got it to work by copying the contents of my auth controller, deleting the file, running php artisan make:controller AuthController , and then pasting the old controller code in.

I wonder why?

What steps does artisan make take to create a controller?

javleds's avatar

This works for me:

Route::group(['prefix'=>'auth', 'namespace' => 'Auth'], function() { Route::get('login', ['as' => '', 'uses' => 'AuthController@login']); });

Other way is:

Route::get('login', ['as' => '', 'uses' => 'Auth\AuthController@login']);

ItsRD's avatar

I started a new project and run into the same issue, got it working now.

This is wat worked for me:

Route::group(['middleware' => ['web'], 'namespace'=>'App\Http\Controllers'], function () {
     Route::auth();
});
Stillfinder's avatar

You can check RouteServiceProvider.php . There is should be something like this: protected $apiNamespace = 'App\Http\Controllers\Api'; .... protected function mapApiRoutes() { Route::prefix('api/v1') ->middleware('api') ->namespace($this->apiNamespace) ->group(base_path('routes/api.php')); }

Please or to participate in this conversation.