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

canadianlover's avatar

Undefined variable $errors on login page

So I'm trying to build an e-commerce site and when I go to /auth/login in my application, I get a Undefined variable: errors. This makes no sense to me because $errors should be available in all views. I've asked this question on stackoverflow) http://stackoverflow.com/questions/37212226/error-with-auth-middleware?noredirect=1#comment61957524_37212226 but didn't get an answer other than to change my Auth controller, which should be set up to work as it comes straight of the box. I can't login or out of my website

AuthController source:


namespace App\Http\Controllers\Auth;

use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
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, ThrottlesLogins;

    /**
     * Where to redirect users after login / registration.
     *
     * @var string
     */
    protected $redirectTo = '/';

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

    /**
     * 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|min:6|confirmed',
        ]);
    }

    /**
     * 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']),
        ]);
    }
}

Login view:


@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <div class="panel panel-default">
                <div class="panel-heading">Login</div>
                <div class="panel-body">
                    <form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }}">
                        {!! csrf_field() !!}

                        <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
                            <label class="col-md-4 control-label">E-Mail Address</label>

                            <div class="col-md-6">
                                <input type="email" class="form-control" name="email" value="{{ old('email') }}">

                                @if ($errors->has('email'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('email') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
                            <label class="col-md-4 control-label">Password</label>

                            <div class="col-md-6">
                                <input type="password" class="form-control" name="password">

                                @if ($errors->has('password'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('password') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-4">
                                <div class="checkbox">
                                    <label>
                                        <input type="checkbox" name="remember"> Remember Me
                                    </label>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-4">
                                <button type="submit" class="btn btn-primary">
                                    <i class="fa fa-btn fa-sign-in"></i>Login
                                </button>

                                <a class="btn btn-link" href="{{ url('/password/reset') }}">Forgot Your Password?</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection```
Any suggestions, I think the advise provided on Stack exchange was unable to solve the problem so I'll ask the question again here. Why am I getting this error if Auth comes straight out of the box?
0 likes
17 replies
SaeedPrez's avatar

@canadianlover your AuthController looks like the default one, have you made any changes to it? If not, run php artistan route:list and show us the result.

ohffs's avatar

Which version of the framework are you on? You might have to put the route inside the 'web' middleware depending which particular minor version you're using.

ohffs's avatar

@Prez heh - I opened the thread in a background tab and took a few minutes before posting and seeing you'd already nipped in like a laravel ninja ;-)

Anyway - it's gone 5pm on a Friday, so I think it's time for some beer and catching up on podcasts - my Friday nights are totally wild these days... ;-) Middle age ftw... ;-)

1 like
SaeedPrez's avatar

@ohffs hahaha, it's not much better here... past 6pm, still at the office, will probably be here couple of more hours, then maybe meet a friend and go for a walk or play some table tennis :) Have a good weekend

canadianlover's avatar

When I run php artistan route:list I get the following error message: Could not open input file: artistan.

canadianlover's avatar

Here's what I get

| Domain | Method                         | URI                                                    | Name         | Action                                                          | Middleware |
+--------+--------------------------------+--------------------------------------------------------+--------------+-----------------------------------------------------------------+------------+
|        | GET|HEAD                       | /                                                      |              | Closure                                                         |            |
|        | GET|HEAD                       | addItem/{productID}                                    |              | App\Http\Controllers\CartController@addItem                     | auth       |
|        | POST                           | auth/login/{one?}/{two?}/{three?}/{four?}/{five?}      |              | App\Http\Controllers\Auth\AuthController@postLogin              | web,guest  |
|        | GET|HEAD                       | auth/login/{one?}/{two?}/{three?}/{four?}/{five?}      |              | App\Http\Controllers\Auth\AuthController@getLogin               | web,guest  |
|        | GET|HEAD                       | auth/logout/{one?}/{two?}/{three?}/{four?}/{five?}     |              | App\Http\Controllers\Auth\AuthController@getLogout              | web,guest  |
|        | GET|HEAD                       | auth/register/{one?}/{two?}/{three?}/{four?}/{five?}   |              | App\Http\Controllers\Auth\AuthController@getRegister            | web,guest  |
|        | POST                           | auth/register/{one?}/{two?}/{three?}/{four?}/{five?}   |              | App\Http\Controllers\Auth\AuthController@postRegister           | web,guest  |
|        | GET|HEAD|POST|PUT|PATCH|DELETE | auth/{_missing}                                        |              | App\Http\Controllers\Auth\AuthController@missingMethod          | web,guest  |
|        | GET|HEAD                       | checkout                                               |              | Closure                                                         | web        |
|        | POST                           | create_payment                                         |              | Closure                                                         | web        |
|        | GET|HEAD                       | home                                                   |              | App\Http\Controllers\HomeController@index                       | auth       |
|        | GET|HEAD                       | item                                                   |              | App\Http\Controllers\ItemController@index                       |            |
|        | POST                           | item                                                   |              | App\Http\Controllers\ItemController@store                       |            |
|        | POST                           | item/create                                            | item.store   | App\Http\Controllers\ItemController@store                       |            |
|        | GET|HEAD                       | item/create                                            | item.create  | App\Http\Controllers\ItemController@create                      |            |
|        | GET|HEAD                       | item/{id}                                              |              | App\Http\Controllers\ItemController@show                        |            |
|        | GET|HEAD                       | item/{item}                                            | item.show    | App\Http\Controllers\ItemController@show                        |            |
|        | PUT|PATCH                      | item/{item}                                            | item.update  | App\Http\Controllers\ItemController@update                      |            |
|        | DELETE                         | item/{item}                                            | item.destroy | App\Http\Controllers\ItemController@destroy                     |            |
|        | GET|HEAD                       | item/{item}/edit                                       | item.edit    | App\Http\Controllers\ItemController@edit                        |            |
|        | GET|HEAD                       | login                                                  |              | App\Http\Controllers\Auth\AuthController@showLoginForm          | guest      |
|        | POST                           | login                                                  |              | App\Http\Controllers\Auth\AuthController@login                  | guest      |
|        | GET|HEAD                       | logout                                                 |              | App\Http\Controllers\Auth\AuthController@getLogout              | web,guest  |
|        | GET|HEAD                       | password/broker/{one?}/{two?}/{three?}/{four?}/{five?} |              | App\Http\Controllers\Auth\PasswordController@getBroker          | web,guest  |
|        | POST                           | password/email                                         |              | App\Http\Controllers\Auth\PasswordController@sendResetLinkEmail | guest      |
|        | GET|HEAD                       | password/email/{one?}/{two?}/{three?}/{four?}/{five?}  |              | App\Http\Controllers\Auth\PasswordController@getEmail           | web,guest  |
|        | POST                           | password/email/{one?}/{two?}/{three?}/{four?}/{five?}  |              | App\Http\Controllers\Auth\PasswordController@postEmail          | web,guest  |
|        | POST                           | password/reset                                         |              | App\Http\Controllers\Auth\PasswordController@reset              | guest      |
|        | GET|HEAD                       | password/reset/{one?}/{two?}/{three?}/{four?}/{five?}  |              | App\Http\Controllers\Auth\PasswordController@getReset           | web,guest  |
|        | POST                           | password/reset/{one?}/{two?}/{three?}/{four?}/{five?}  |              | App\Http\Controllers\Auth\PasswordController@postReset          | web,guest  |
|        | GET|HEAD                       | password/reset/{token?}                                |              | App\Http\Controllers\Auth\PasswordController@showResetForm      | guest      |
|        | GET|HEAD|POST|PUT|PATCH|DELETE | password/{_missing}                                    |              | App\Http\Controllers\Auth\PasswordController@missingMethod      | web,guest  |
|        | POST                           | register                                               |              | App\Http\Controllers\Auth\AuthController@postRegister           | web,guest  |
|        | GET|HEAD                       | register                                               |              | App\Http\Controllers\Auth\AuthController@getRegister            | web,guest  |
|        | GET|HEAD                       | removeItem/{productID}                                 |              | App\Http\Controllers\CartController@removeItem                  | auth       |
+--------+--------------------------------+--------------------------------------------------------+--------------+-----------------------------------------------------------------+------------+```
ohffs's avatar

@Prez you too! I hope the weather in Sweden is a mysteriously nice as it is over here in Scotland just now so your walk is nice :-) It's actually not raining just now - it's weird! ;-)

Anyway - I've given the cat a load of tuna so it stops pestering me for a while - beer time! :-)

SaeedPrez's avatar

@ohffs Thank you! It's been really sunny here last week, but the weather is crazy, a couple of weeks ago we had snow out of nowhere :) Cheers

@canadianlover hm..

  1. It looks like you have multiple login/logout routes
  2. Some of your routes are not using the web middleware which would disable sessions and so on.
SaeedPrez's avatar

@canadianlover just because you are blind or #¤%! and don't understand, it doesn't mean we didn't already solve your problem hours ago. So please get off your high horse and stop demanding, no one here owes you anything..

Funny thing is I was actually putting in more effort to try help you fix your routes file, but I know better now... In fact, next time I'll make an effort not to help you.

PS. Routes file help deleted :)

canadianlover's avatar

I was not demanding that you answer my question. I was simply trying to bring the conversation back on topic. I didnt notice the previous help you provided. I am sorry.

SaeedPrez's avatar

Sure I was having some fun with ohffs, but you were never forgotten. Whenever you replied, I replied within minutes. Just scroll up, the proof is right there. There's no point in trying making it sound like you were ignored.

As you can see from the screenshot i posted, both me and ohffs tried to help you and we told you what your problem was.

Also, ohffs went away ~6 hours ago and my last 2 posts were for you where in the last one I was trying to help you even further so you could fix your routes file (the post I deleted). You did not answer for ~4 hours and then you come back demanding an answer that was already given to you twice before.

canadianlover's avatar

Really, swear to god I was demanding help, I just didn't notice your response to my original post. Agian, I'm sorry. I am still a newbie and I'm not sure what the forum rules are. Thanks for you help and I'm sorry for being rude.

SaeedPrez's avatar

Alright, let's put an end to this. Good day/night and good luck with your project.

abdulrehmandev's avatar

I had the same issue.

As told by @saeedprez @ohffs

You need to update your boot() in app/providers/RouteServiceProvider.php and add 'web' middleware.

See below example

public function boot() { $this->configureRateLimiting();

    $this->routes(function () {
        Route::prefix('api')
            ->middleware('api')
            ->namespace($this->namespace)
            ->group(base_path('routes/api.php'));

        Route::prefix('instructor')
            ->middleware(['web'])
            ->namespace($this->namespace)
            ->group(base_path('routes/instructor.php'));

        Route::prefix('student')
            ->middleware(['web'])
            ->namespace($this->namespace)
            ->group(base_path('routes/student.php'));

        Route::prefix('admin')
            ->middleware(['web'])
            ->namespace($this->namespace)
            ->group(base_path('routes/admin.php'));

        Route::middleware('web')
            ->namespace($this->namespace)
            ->group(base_path('routes/web.php'));
    });
}

Please or to participate in this conversation.