2
votes

I've followed Laravel 5.3 upgrade guide, which says to add an unauthenticated method in App\Exceptions\Handler.

However, I get the following error when it gets called by the Auth system:

FatalThrowableError in Handler.php line 59: Type error: Argument 2 passed to App\Exceptions\Handler::unauthenticated() must be an instance of App\Exceptions\AuthenticationException, instance of Illuminate\Auth\AuthenticationException given, called in /Users/Username/Development/ProjectName/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php on line 135

I've been searching for the last half hour and couldn't find a solution.

Any help?

3
Either add use App\Exceptions\AuthenticationException; at the beggining of the file that uses the AuthenticationException, or change the AuthenticationException to \App\Exceptions\AuthenticationException where you use it inside your code.Christos Lytras
I didn't create an AuthenticationException class (I didn't need it and the Laravel upgrade guide didn't mention it), it is supposed to be provided by Laravel itself.Alan
Can you check the app/Http/Kernel.php if the can middleware points to \Illuminate\Auth\Middleware\Authorize::class defined in protected $routeMiddleware array like this 'can' => \Illuminate\Auth\Middleware\Authorize::class?Christos Lytras
Sorry for the delay, I had to put this project away for a while. Yes, though, it does point to that class: 'can' => \Illuminate\Auth\Middleware\Authorize::class,Alan

3 Answers

3
votes

Check how your Handler.php file compares to the 5.3 branch version here: https://github.com/laravel/laravel/blob/5.3/app/Exceptions/Handler.php

Note the unauthenticated() method in Handler.php expects an instance of \Illuminate\Auth\AuthenticationException. Make sure use Illuminate\Auth\AuthenticationException; is included at the top of the file.

0
votes

In my case, i just deleted whoops... or restore the default Handler.php

0
votes

I had this Error 500 inexplicable issue while upgrading from Laravel 5.2 to 5.3. No laravel error logs in storage/logs, no Apache error logs. no issue with .env, debug was turned on, no broken .htaccess directives, plus php artisan could not run. Tried everything until I looked in the PHP error logs and found:

PHP Fatal error:  Uncaught Error: Undefined constant 'Illuminate\Auth\AuthenticationException' in C:\code\laravel-project\vendor\laravel\framework\src\Illuminate\Container\Container.php:79

So I did what @jon suggested and compared my Handler.php file with the fresh laravel one and found this:

In your App/Exceptions/Handler.php make sure that the classes in the $dontreport array are referenced as either strings in quotes:

        '\Illuminate\Auth\AuthenticationException',
        '\Illuminate\Auth\Access\AuthorizationException',
        '\Symfony\Component\HttpKernel\Exception\HttpException',
        '\Illuminate\Database\Eloquent\ModelNotFoundException',
        '\Illuminate\Session\TokenMismatchException',
        '\Illuminate\Validation\ValidationException',

or this way:

        \Illuminate\Auth\AuthenticationException::class,
        \Illuminate\Auth\Access\AuthorizationException::class,
        \Symfony\Component\HttpKernel\Exception\HttpException::class,
        \Illuminate\Database\Eloquent\ModelNotFoundException::class,
        \Illuminate\Session\TokenMismatchException::class,
        \Illuminate\Validation\ValidationException::class,

For some reason I found mine to not have the quotes and fixing that got rid of the Error 500.