Laravel 身份验证与新模型 &守卫失败:未定义索引:模型 [英] Laravel authentication with new model & guard fails: Undefined index: model

查看:20
本文介绍了Laravel 身份验证与新模型 &守卫失败:未定义索引:模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用附加模型验证我的 Laravel 应用程序 (5.8)警卫.问题是,我在以下登录方法中收到未定义索引:模型"错误.任何想法我做错了什么?我在 5.7 版本的 Laravel 中使用了这种集成,并且在那里运行没有任何问题.

I'm trying to authenticate my Laravel application (5.8) with an additional model & guard. The problem, I receive a "Undefined index: model" error during the following login approach. Any ideas what i'm doing wrong? I've used this integration in an 5.7 Version of Laravel and it worked there without any problems.

 auth()->guard('partner')->login($partner);

代码片段:

合作伙伴模型(附加设置)

class Partner extends Authenticatable  {

protected $guard = 'partner';

    public function getRouteKeyName()
    {
        return 'uuid';
    }

}

守卫 (config.auth.php)

Guards (config.auth.php)

'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'partner' => [
            'driver' => 'session',
            'provider' => 'partners',
        ],
],

提供者 (config.auth.php)

Providers (config.auth.php)

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => AppModelsUser::class,
    ],

    'partners' => [
        'driver' => 'eloquent',
        'table' => AppModelsPartner::class,
    ],
],

中间件组 (kernel.php)

Middleware Gorup (kernel.php)

protected $middlewareGroups = [

        'partner' => [
            AppHttpMiddlewareEncryptCookies::class,
            IlluminateCookieMiddlewareAddQueuedCookiesToResponse::class,
            IlluminateSessionMiddlewareStartSession::class,
            //IlluminateSessionMiddlewareAuthenticateSession::class,
            IlluminateViewMiddlewareShareErrorsFromSession::class,
            AppHttpMiddlewareVerifyCsrfToken::class,
        ],

];

RouteServiceProvider

RouteServiceProvider

  protected function mapPartnerRoutes()
    {
        Route::prefix('partner')
            ->middleware(['partner'])
            ->namespace($this->namespace)
            ->group(base_path('routes/partner.php'));

    }

应用程序框架错误

推荐答案

我认为您错过了在 partners 身份验证提供程序中配置模型,即:

I think you miss to configure a model in your partners auth provider, i.e.:

'partners' => [
    'driver' => 'eloquent',
    //'table' => AppModelsPartner::class,
    'model' => AppModelsPartner::class,
],

这篇关于Laravel 身份验证与新模型 &守卫失败:未定义索引:模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆