Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

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,795
Reaction score
2,140
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
898
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:
 
Upvote 0
Status
Not open for further replies.
Back
Top