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
Because we need to change the Auth config file (you can find it in config/auth. php), and change the users provider model from “User::class” to “YourNewModel::class”, in this case “Administrator::class”. Using the Administrator model. * Get a validator for an incoming registration request.
Just run php artisan make:auth and php artisan migrate in a fresh Laravel application. Then, navigate your browser to http://your-app.test/register or any other URL that is assigned to your application. These two commands will take care of scaffolding your entire authentication system!
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,
],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With