【发布时间】:2017-04-25 22:53:25
【问题描述】:
我关注了Laravel 5.3 upgrade guide,它说要在App\Exceptions\Handler 中添加一个unauthenticated 方法。
但是,当它被 Auth 系统调用时,我收到以下错误:
Handler.php 第 59 行中的 FatalThrowableError: 类型错误:传递给 App\Exceptions\Handler::unauthenticated() 的参数 2 必须是 App\Exceptions\AuthenticationException 的实例,给出 Illuminate\Auth\AuthenticationException 的实例,在 /Users/Username/Development/ProjectName/vendor/ 中调用laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php 在第 135 行
我一直在寻找最后半小时,但找不到解决方案。
有什么帮助吗?
【问题讨论】:
-
要么在使用
AuthenticationException的文件的开头添加use App\Exceptions\AuthenticationException;,要么将AuthenticationException更改为\App\Exceptions\AuthenticationException,以便在代码中使用它。 -
我没有创建AuthenticationException类(我不需要,Laravel升级指南也没有提到),应该是Laravel自己提供的。
-
如果
can中间件指向\Illuminate\Auth\Middleware\Authorize::class在protected $routeMiddleware数组中定义的'can' => \Illuminate\Auth\Middleware\Authorize::class这样'can' => \Illuminate\Auth\Middleware\Authorize::class,你能检查app/Http/Kernel.php吗? -
抱歉耽搁了,我不得不把这个项目搁置一段时间。是的,不过,它确实指向那个类:
'can' => \Illuminate\Auth\Middleware\Authorize::class,
标签: php laravel authentication exception upgrade