gvauditor's avatar

Change users tablename

Hi to all,

In version 5.1 If I want to change the name of users to any name, what rework or what file/s do I also need to make changes?

In config/auth.php i change this line:
'table' => 'users',

But I think changing that one is not enough since I can't retrieve the authenticated user using this facade, $user = Auth::user();

Thank you.

0 likes
7 replies
bimalshah72's avatar

Also you need to change model in the same file

'model' => 'App\Models\User', //whatever here

bimalshah72's avatar

and in the model itself

verify protected $table property and its value

gvauditor's avatar

Sorry but i'm still new to laravel and did not quite get what you mean. I can see this on the same file

'model' => App\User::class,

what do you mean change whatever here?

Thank you.

mstnorris's avatar

@gvauditor within your app/User.php class, add the following protected property:

protected $table = 'whatever';
1 like
bimalshah72's avatar

@gvauditor

Where is your User class ? what is name space of it?

Make sure following::

if your database table name is 'users' and class name is 'User' then no need to add any protected $table property in 'User' model

in auth.config you have to set correct $model and $table where $model should be with proper namepaced

gvauditor's avatar

Thanks everyone guys, I needed to add that line in the app/User.php for it to work.

hashik's avatar

i changed auth table, and registration was successfull, but i can not login after logout

Please or to participate in this conversation.