Change table users Auth Laravel 5.1

Asked

Viewed 2,727 times

10

I’m developing a system using Laravel 5.1 and I don’t want to use English tables. I’m actually trying to maintain the pattern followed here at the company.

I wonder if I can use the Auth or OAuth and change the table of users for users, and consequently their fields, for example: password instead of password. In addition to adding more personal information and access levels.

Someone has done something similar?

  • 3

    Can yes, in the configuration file config/auth.php

2 answers

2

Yes.

In the archive app/auth.php you have to change those two lines:

'model' => 'App\User',
'table' => 'users',

Switch to the table name you created.

Remembering that the table name in the bank should be Plural and in Laravel the Model should be in Singular.

2

First make table name change at config/auth.php:

'table' => 'users',

Add the variable $username to the archive app/Http/Controllers/Auth/Authcontroller.php

protected $username = 'username';

To change the columns name, password, etc., you will need to create a new driver for auth. A common example is an LDAP driver where LDAP fields are different from those used by the framework.

  • 1

    Bruno, changing the config the way you showed does not solve the problem as it depends on the auth driver used (eloquent or database).

  • @gmsantos you’re right, thanks for the remark!

  • Did you get what you wanted? If yes, mark the correct answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.