Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Allenek's avatar

Using a different table as a login instead of default "user"

Hello, im trying to use an existing table to provide login credentials instead of the default user one, in the app/user.php handle method i have added a line "protected $table = 'employees'; protected $fillable = [ 'Imie', 'Nazwisko', 'Email','Pesel','Uprawnienia' ]; "

Trying to use the employees table instead of the default users one and providing details for which Email would be the login and Pesel would be the password, the question is where do i actually point to laravel that Pesel field from table called employees should be used as a password instead of the default one, i have tried editing providers in config/auth.php but then i got a http://prntscr.com/q8wvlm error so i would like to keep the default structure intact but just point the auth to use fields from another table as the login/password instead. The question is, how do i achieve that?

Laravel 5.8, generated the authentication with "php artisan make:auth"

0 likes
2 replies
TheRealHyveMind's avatar

This should be able to give you some further insight into what you're trying to achieve;

https://laracasts.com/discuss/channels/general-discussion/using-different-table-for-authentication-in-laravel

The main thing I would say is there really isn't much harm in just leaving it on the User model. If there isn't an explicit need to move it, you probably shouldn't. Other developers who get involved might not think to look at the Employees table, and, what happens when you need to add to or adjust your codebase in the future?

Keeping it on the User model makes more sense because what if suddenly the scope of your project changes, and now you also need to add Employers, Managers, Administrators, or something else? Suddenly, your whole user system breaks apart.

However, if you keep it locked to your User model, you can handle all user elements in an easy place, and use either roles, or even relationships to other models to handle the various elements you're planning to work on.

Allenek's avatar

Okay so i have changed the required things, my employee.php looks like this

<?php

namespace App;

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Auth\Authenticatable as AuthenticableTrait;
use Illuminate\Database\Eloquent\Model;

class Employee extends Model implements Authenticatable
{
    use AuthenticableTrait;
}

my auth.php is

    'defaults' => [
        'guard' => 'web',
        'passwords' => 'employees',
    ],



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

        'api' => [
            'driver' => 'token',
            'provider' => 'users',  //tried with employees as well 
            'hash' => true, //tried both hashed and not hashed password
        ],
    ],

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ],

    'employees' => [
        'driver' => 'eloquent',
          'model' => App\Employee::class,
        ],

but whenever i try to log i get the http://prntscr.com/q9cbvh error

Thats how my email/pesel(login/password) looks like http://prntscr.com/q9cc6r Thats the employees table in database http://prntscr.com/q9cdiw

I have tried with and without hashes - can't get it working also i don't really know how to debug it with dd(); as im not handling any requests in the controller

Please or to participate in this conversation.