'Laravel nova / add second login

Im creating a Website with Laravel nova. When installing nova by default you get a login, a users table and a dashboard. Now I need to add a second login for another Tabel user_b. Is this possible and how ca I do it? Is there a way to edit and customize the components in the vendor/laravel/nova folder?



Solution 1:[1]

Lets say you have admins table. You need to add a guard first.

In config/auth.php update guards and providers like this.

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

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
            'hash' => false,
        ],
        'admin' => [
            'driver' => 'session',
            'provider' => 'admins',
        ],
    ],
    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\User::class,
        ],
        'admins' => [
            'driver' => 'eloquent',
            'model' => App\Models\Admin::class,
        ],

        // 'users' => [
        //     'driver' => 'database',
        //     'table' => 'users',
        // ],
    ],

If you have admins table you need a model. So create model Admin. php artisan make:model Admin and you need to modify it like this;

<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Nova\Auth\Impersonatable;

class Admin extends Authenticatable
{
    use Notifiable;
    use AuthenticationLoggable;
    use Impersonatable;
  

    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    protected $casts = [
        'permissions' => 'array',
    ];
}

In your config/nova.php change guard to admin

 'guard' => 'admin',

And your seperate login process implemented to nova.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 xuma