Changing Laravel authenticate model

Results 1 to 6 of 6
  1. #1
    Registered briian is offline
    MemberRank
    May 2017 Join Date
    20Posts

    Changing Laravel authenticate model


    RaGEZONE Recommends

    RaGEZONE Recommends

    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


  2. #2
    Would You Kindly? Bola is online now
    DeveloperRank
    Dec 2011 Join Date
    BrazilLocation
    1,503Posts

    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);

  3. #3
    Registered briian is offline
    MemberRank
    May 2017 Join Date
    20Posts

    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.

  4. #4
    ◝(⁰▿⁰)◜Smile◝ (⁰▿⁰)◜ Taiga is online now
    ModeratorRank
    May 2007 Join Date
    InternetLocation
    2,476Posts

    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';
    Moderator & Developer
    I CAN NOT HELP YOU WITH YOUR SERVER, USE THE CORRECT HELP SECTION INSTEAD.
    I AM ONLY TAIGA ON RAGEZONE!
    BE CAREFUL WITH IMPOSTORS!


    DO NOT PM ME FOR GAME RELATED QUESTIONS, THESE MESSAGES WILL BE IGNORED!

    The Rules | Discord | MMORPG Extra | Contact Me


  5. #5
    Registered briian is offline
    MemberRank
    May 2017 Join Date
    20Posts

    Re: Changing Laravel authenticate model

    hoping that works taiga

  6. #6
    Registered briian is offline
    MemberRank
    May 2017 Join Date
    20Posts

    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




Advertisement