Laravel authentication with new model & guard fails: Undefined index: model

送分小仙女□ 提交于 2020-03-15 06:10:08

问题


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);

CodeSnippets:

Partner Model (additional Settings)

class Partner extends Authenticatable  {

protected $guard = 'partner';

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

}

Guards (config.auth.php)

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

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

Providers (config.auth.php)

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\Models\User::class,
    ],

    'partners' => [
        'driver' => 'eloquent',
        'table' => \App\Models\Partner::class,
    ],
],

Middleware Gorup (kernel.php)

protected $middlewareGroups = [

        'partner' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            //\Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
        ],

];

RouteServiceProvider

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

    }

Application frames Error


回答1:


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

'partners' => [
    'driver' => 'eloquent',
    //'table' => \App\Models\Partner::class,
    'model' => \App\Models\Partner::class,
],


来源:https://stackoverflow.com/questions/55308874/laravel-authentication-with-new-model-guard-fails-undefined-index-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!