使用新模型和新版本的Laravel身份验证保护失败:未定义的索引:模型 [英] Laravel authentication with new model & guard fails: Undefined index: model
问题描述
我正在尝试使用其他模型&来验证我的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' => App\Models\User::class,
],
'partners' => [
'driver' => 'eloquent',
'table' => \App\Models\Partner::class,
],
],
中间件Gorup (kernel.php)
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
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' => \App\Models\Partner::class,
'model' => \App\Models\Partner::class,
],
这篇关于使用新模型和新版本的Laravel身份验证保护失败:未定义的索引:模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!