• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

Changing Laravel authenticate model

Status
Not open for further replies.
Newbie Spellweaver
Joined
May 13, 2017
Messages
31
Reaction score
1
Hey all,

I was trying to find how to change the authenticatable model in Laravel to use `Player` instead (model I have made but haven't touched yet) but all of the resources I have found online are for past versions of laravel. Has anyone done this and has a good resource for it?

excuse any typos im tired as hell.

thanks
 
Shh, quiet, you might piss somebody off
Developer
Joined
Dec 23, 2011
Messages
1,797
Reaction score
2,169
in version 5.4 with multi auth

if you're looking to add a new auth without change default one

duplicate this following line in auth.php inside config from laravel package

Code:
'web' => [ // RENAME WEB TO A NEW GUARD SERVICE
            'driver' => 'session',
            'provider' => 'users', // PLACE HERE THE USER PROVIDER NAME
        ],
also duplicate this following line
Code:
        'users' => [ // CHANGE TO A NEW USER PROVIDER NAME
            'driver' => 'eloquent',
            'model' => App\Models\User::class, // CHANGE TO A MODEL THAT EXTENDS FROM AUTHENTICATE CLASS 
        ],

then you can create your authentication service in the guard using Auth::guard('newguardname')->attempt([ 'login' => 'alooo', 'password' => 'md5encodedstring'], false);
 
Upvote 0
Newbie Spellweaver
Joined
May 13, 2017
Messages
31
Reaction score
1
I'm fine with changing the default one, I don't think I'll need it, right? The db will need to access the players table, never users.
 
Upvote 0
◝(⁰▿⁰)◜Smile◝ (⁰▿⁰)◜
Developer
Joined
May 29, 2007
Messages
2,167
Reaction score
899
You can change the table name by adding an override to the $table property in the users model.
You could just add:
Code:
public $table = 'Players';
 
Upvote 0
Newbie Spellweaver
Joined
May 13, 2017
Messages
31
Reaction score
1
The fix for this was as Taiga suggested to add $protected table = "players"; in the User model. I also had to change config/auth.php to 'players' as I'd originally done and use it like that.

Also, this assumes that the user is using `php artisan make:auth` and using that out of the box login functionality, which can be overridden by writing a function `public function login() {}` in the LoginController and including custom code there.

This link is helpful for future queries about this: https://asklagbox.com/blog/auth-scaffold-customizing
 
Upvote 0
Status
Not open for further replies.
Back
Top