Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the user model in laravel to use other table for authentication than users?

How can i change the default user model to use other database table instead of users table in laravel 5.3, is adding

protected $table = 'my_table_name';

will do everything or do i have to change the providers and all.

I dont wish to use multiple authentication like admin, customers etc i just want one authentication model but not with the table "users".

I am preparing an application which has multiple type of users like admin, astrologers and users. all of them have different attributes so i cant use single model with access control in it so i have decided to divide the application into 3 websites to use single database and host them in subdomains like

admin.mywebsite.com
astrologer.mywebsite.com
www.mywebsite.com

earlier i was using multiauth/hesto plugin but for some strange reason it's not redirecting me to the intended url after login and registration. any help will be appreciated.

like image 563
Taj Khan Avatar asked Oct 30 '25 19:10

Taj Khan


1 Answers

check this one Using Different Table for Auth in Laravel

Edit app/config/auth.php to change the table.

'table' => 'yourTable'
'model' => 'YourModel',

then your model:

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

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

    protected $table = 'your_table';
    protected $fillable = array('UserName', 'Password');    
    public $timestamps = true;
    public static $rules = array();    
}
like image 195
ashanrupasinghe Avatar answered Nov 02 '25 11:11

ashanrupasinghe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!