问题
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