Changing Laravel authenticate model
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
Re: Changing Laravel authenticate model
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);
Re: Changing Laravel authenticate model
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.
Re: Changing Laravel authenticate model
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';
Re: Changing Laravel authenticate model
Re: Changing Laravel authenticate model
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