我正在使用Laravel 5.5,并试图为用户和管理员实现多重身份验证.当我试图在浏览器中调用管理员登录表单时,我遇到了这个错误.

错误:

App\Exceptions\Handler::unauthenticated($request,App\Exceptions\AuthenticationException$exception)的声明应与illumb\Foundation\Exceptions\Handler::unauthenticated($request,illumb\Auth\AuthenticationException$exception)兼容

以下是我在app/Exceptions/Handler中未经验证的函数:

 protected function unauthenticated($request, AuthenticationException $exception)
    {
        if ($request->expectsJson()) {
            return response()->json(['error' => 'Unauthenticated.'], 401);
        }
        $guard = array_get($exception->guards(), 0);
        switch ($guard) {
            case 'admin':
                $login = 'admin.login';
                break;
            default:
                $login = 'login';
                break;
        }
        return redirect()->guest(route($login));
    }

请帮我解决这个问题.

推荐答案

你忘了在文件顶部加use Illuminate\Auth\AuthenticationException

Laravel相关问答推荐

为什么Laravel在API请求时返回BadMethodCallException?

laravel如何在Blade 模板中将元素添加到数组

Laravel 联合和分页

嵌套数组请求的 Laravel 验证,其中如果整数之一为零,则另一个应大于零

Laravel Livewire 组件属性在 div 类中为空

如何在数据来自Rest API的flutter中创建下拉类别名称列表?

使用 laravel 根据当月显示注册用户列表

找不到 Laravel 5 类日志(log)

Laravel 5.1 重命名项目

Laravel 5:完整性约束违规:1452 无法添加或更新子行:外键约束失败

Laravel 和 PHPStorm 项目的 gitignore 中包含什么?

Laravel 说 Auth guard [] 没有定义

Laravel 5 - 为包创建 Artisan 命令

Laravel 5.1-5.8 中以前的路由名称

Laravel / Eloquent内存泄漏重复检索相同的记录

如何卸载 Laravel Passport

Laravel:array_merge():参数#2不是数组错误

Laravel 中的 isDirty() 是什么意思?

在哪里放置 Blade::extend

如何在脚本文件中使用 Laravel Blade?