Laravel 5.3 unauthorized() AuthenticationException 致命错误
Laravel 5.3 unauthorized() AuthenticationException fatal error
我关注了 Laravel 5.3 upgrade guide,它说要在 App\Exceptions\Handler
.
中添加一个 unauthenticated
方法
但是,当它被 Auth 系统调用时,我收到以下错误:
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
最近半个小时我一直在寻找解决方案,但找不到解决方案。
有什么帮助吗?
在此处查看您的 Handler.php 文件与 5.3 分支版本的比较:https://github.com/laravel/laravel/blob/5.3/app/Exceptions/Handler.php
请注意 Handler.php 中的 unauthenticated() 方法需要一个 \Illuminate\Auth\AuthenticationException
的实例。确保 use Illuminate\Auth\AuthenticationException;
包含在文件的顶部。
就我而言,我只是删除了 whoops... 或恢复默认值 Handler.php
我在从 Laravel 5.2 升级到 5.3 时遇到了这个 Error 500
无法解释的问题。 storage/logs
中没有 laravel 错误日志,没有 Apache 错误日志。 .env
没有问题,调试已打开,没有损坏 .htaccess
指令,加上 php artisan
不能 运行。尝试了所有方法,直到我查看 PHP 错误日志并发现:
PHP Fatal error: Uncaught Error: Undefined constant 'Illuminate\Auth\AuthenticationException' in C:\code\laravel-project\vendor\laravel\framework\src\Illuminate\Container\Container.php:79
所以我按照@jon 的建议进行了比较,并将我的 Handler.php 文件与新的 laravel 文件进行了比较,发现:
在您的 App/Exceptions/Handler.php 中,确保 $dontreport
数组中的 类 被引用为引号中的任一字符串:
'\Illuminate\Auth\AuthenticationException',
'\Illuminate\Auth\Access\AuthorizationException',
'\Symfony\Component\HttpKernel\Exception\HttpException',
'\Illuminate\Database\Eloquent\ModelNotFoundException',
'\Illuminate\Session\TokenMismatchException',
'\Illuminate\Validation\ValidationException',
或者这样:
\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,
出于某种原因,我发现我的没有去掉 Error 500
.
的引号和修正
我关注了 Laravel 5.3 upgrade guide,它说要在 App\Exceptions\Handler
.
unauthenticated
方法
但是,当它被 Auth 系统调用时,我收到以下错误:
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
最近半个小时我一直在寻找解决方案,但找不到解决方案。
有什么帮助吗?
在此处查看您的 Handler.php 文件与 5.3 分支版本的比较:https://github.com/laravel/laravel/blob/5.3/app/Exceptions/Handler.php
请注意 Handler.php 中的 unauthenticated() 方法需要一个 \Illuminate\Auth\AuthenticationException
的实例。确保 use Illuminate\Auth\AuthenticationException;
包含在文件的顶部。
就我而言,我只是删除了 whoops... 或恢复默认值 Handler.php
我在从 Laravel 5.2 升级到 5.3 时遇到了这个 Error 500
无法解释的问题。 storage/logs
中没有 laravel 错误日志,没有 Apache 错误日志。 .env
没有问题,调试已打开,没有损坏 .htaccess
指令,加上 php artisan
不能 运行。尝试了所有方法,直到我查看 PHP 错误日志并发现:
PHP Fatal error: Uncaught Error: Undefined constant 'Illuminate\Auth\AuthenticationException' in C:\code\laravel-project\vendor\laravel\framework\src\Illuminate\Container\Container.php:79
所以我按照@jon 的建议进行了比较,并将我的 Handler.php 文件与新的 laravel 文件进行了比较,发现:
在您的 App/Exceptions/Handler.php 中,确保 $dontreport
数组中的 类 被引用为引号中的任一字符串:
'\Illuminate\Auth\AuthenticationException',
'\Illuminate\Auth\Access\AuthorizationException',
'\Symfony\Component\HttpKernel\Exception\HttpException',
'\Illuminate\Database\Eloquent\ModelNotFoundException',
'\Illuminate\Session\TokenMismatchException',
'\Illuminate\Validation\ValidationException',
或者这样:
\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,
出于某种原因,我发现我的没有去掉 Error 500
.