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

Allaudeen's avatar

Using different Table for Authentication in Laravel

I tried with the default user table for Laravel Auth purpose,

Now i am changing it to the admin Table

So i refereed http://laravel-recipes.com/recipes/12/changing-your-authentication-table

Accordingly i tried to change the Table name as admin in the auth.php

'model' => 'User',
'table' => 'users',

to

'model' => 'AdminModel',
'table' => 'admin',

And in the AdminModel i have protected $table = 'admin';

And i got the error

Class AdminModel contains 6 abstract methods and must therefore be declared abstract or implement the remaining methods (Illuminate\Auth\UserInterface::getAuthIdentifier, Illuminate\Auth\UserInterface::getAuthPassword, Illuminate\Auth\UserInterface::getRememberToken, ...)

Is there anything is should change rather than here >

Here is my AdminModel :

<?php
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class AdminModel extends Eloquent implements UserInterface, RemindableInterface 
{
    protected $table = 'admin';
    protected $fillable = array('UserName', 'Password');    
    public $timestamps = true;
    public static $rules = array();    
}
0 likes
3 replies
az_iar's avatar
az_iar
Best Answer
Level 4

you should also use the UserTrait and RemindableTrait

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class AdminModel extends Eloquent implements UserInterface, RemindableInterface 
{
    use UserTrait;
    use RemindableTrait;

    protected $table = 'admin';
    protected $fillable = array('UserName', 'Password');    
    public $timestamps = true;
    public static $rules = array();    
}

3 likes
digitlimit's avatar

I am creating an Adminpanel package and currently doing this in my AdminpanelServiceProvider

    $segment = Request::segments(); //check if we are in adminpanel URL e.g http://site.com/adminpanel
    if(head($segment) == config('adminpanel.base_url', 'adminpanel'))
    {
        config(['auth.model' => config('adminpanel.auth_model', \Digitlimit\Adminpanel\Models\AdminpanelUser::class)]);
        config(['auth.table' => config('adminpanel.auth_table', 'adminpanel_users')]);
    }

I am simply changing default authentication model and table located in config\auth.php at runtime

Please or to participate in this conversation.