Laravel basic auth using another table for credentials.
To implement basic authentication in Laravel using a table other than the default users table for storing credentials, follow these steps:
- Create a new migration file for the table that will store the authentication data.
 
php artisan make:migration create_auth_table --create=auth_users
- Define the schema for the new table in the 
up()method of the migration file. 
public function up()
{
    Schema::create('auth_users', function (Blueprint $table) {
        $table->id();
        $table->string('name');
        $table->string('email')->unique();
        $table->timestamp('email_verified_at')->nullable();
        $table->string('password');
        $table->rememberToken();
        $table->timestamps();
    });
}
- Run the migration to create the table.
 
php artisan migrate
- Update the 
authguard in theapp/Providers/AuthServiceProvider.phpfile to use the new table. 
protected $guards = [
    'web' => [
        'driver' => 'session',
        'provider' => 'users', // Change this to the name of your table
    ],
];
- Update the 
Authmodel in theapp/Models/Auth.phpfile to use the new table. 
protected $table = 'auth_users';
- Update the 
Usermodel in theapp/Models/User.phpfile to extend theAuthenticatableinterface from theIlluminate\Foundation\Auth\Userclass instead of theAuthenticatableinterface from theIlluminate\Auth\Authenticatableclass. 
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
    // ...
}
- Update the 
Usermodel in theapp/Models/User.phpfile to use the new table name in the$tableproperty. 
protected $table = 'auth_users';
- Update the 
Usermodel in theapp/Models/User.phpfile to use the new table name in the$fillableproperty. 
protected $fillable = [
    'name', 'email', 'password',
];
- Update the 
Usermodel in theapp/Models/User.phpfile to use the new table name in the$guardNameproperty. 
protected $guardName = 'web';
- Update the 
AuthServiceProviderin theapp/Providers/AuthServiceProvider.phpfile to use the new table name in theboot()method. 
public function boot()
{
    $this->app->make(Authenticator::class)->configure('guard', function ($guard) {
        $guard->defaults([
            'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKWxm6DBjrPj6eZNvaFasIuMwDQifK6CEq0omfBMhaeM4fBC1Bdn18FD2aIDLj4NQj0zJ6SgZ64add1pq8' // Password is for testing purpose only.
        ]);
        $guard->provider(function ($app, $defaultGuard = null) {
            return Auth::provider($this->app['config']['auth.defaults.guard'] ?? 'web');
        });
    });
}
- Update the 
AuthServiceProviderin theapp/Providers/AuthServiceProvider.phpfile to use the new table name in theboot()method. 
public function boot()
{
    $this->app->make(Authenticator::class)->configure('guard', function ($guard) {
        $guard->defaults([
            'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKWxm6DBjrPj6eZNvaFasIuMwDQifK6CEq0omfBMhaeM4fBC1Bdn18FD2aIDLj4NQj0zJ6SgZ64add1pq8' // Password is for testing purpose only.
        ]);
        $guard->provider(function ($app, $defaultGuard = null) {
            return new UserProvider($app['db'], 'auth_users'); // Use your table name here
        });
    });
}
- Update the 
routes/web.phpfile to use the new table name in themiddlewareproperty of the routes that require authentication. 
Route::middleware(['auth:web'])->group(function () {
    // ...
});
- Update the 
app/Http/Kernel.phpfile to use the new table name in the$routeMiddlewareproperty. 
protected $routeMiddleware = [
    // ...
    'auth:web' => \App\Http\Middleware\Authenticate::class,
];
Now, Laravel will use the new table for storing authentication data.