Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rodzzlessa's avatar

change users table name

So I changed the users table to members in a laravel 5 application. I also changed the config/Auth file to represent that. However when I try to register a user it gives me the error that's it's looking for "Database.users".

here is my auth array:

return [

 'driver' => 'eloquent',
 'model' => 'TGLD\Members\Member',
 'table' => 'members',
 'password' => [
  'email' => 'emails.auth.password',
  'table' => 'password_resets',
  'expire' => 60,
 ],

];

this is the error:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'task_manager.users' doesn't exist (SQL: select count(*) as aggregate from `users` where `username` = rodzzlessa)
0 likes
10 replies
bashy's avatar

Are you using this to change it?

/*
 |--------------------------------------------------------------------------
 | Authentication Table
 |--------------------------------------------------------------------------
 |
 | When using the "Database" authentication driver, we need to know which
 | table should be used to retrieve your users. We have chosen a basic
 | default value but you may easily change it to any table you like.
 |
 */
 'table' => 'users',

Need to have "database" set as the driver for that to come into effect?

2 likes
rodzzlessa's avatar

@bashy i update my answer to show my auth array. Your saying if i want to change the table name I can't use eloquent?

bestmomo's avatar

@bashy just says you to change table name in configuration (auth.php) and that must work :

 'table' => 'myUserTable',
bashy's avatar

If you only change the table in that file, it won't do anything. You need to set it to "database" instead of "eloquent". But I think you want eloquent so changing the "model" part is right. The comments state that.

Have you set the table in your Member model?

1 like
acsakshay's avatar

You need to search for 'unique:users' in 'app/Services/Registrar.php' and replace the users part with your table name 'members' => 'unique:members'

Let me explain. The error that you are getting is with validator function which needs to validate emails as unique entity. Since the Validator class does not know from which table to validate the entered email id, we need to pass the table name 'users' which is by default or 'members' as in your case.

Also make sure to do following changes

  1. config/Auth:- 'table' => 'members',
  2. app/User.php:-

class User extends Model implements AuthenticatableContract, CanResetPasswordContract { use Authenticatable, CanResetPassword;
/** ----------- Add this line in ----------- * The database table used by the model for authentication. * * @var string */ protected $table = 'members';

1 like
bestmomo's avatar

Hope he has reached his goal in 4 monthes ^^

1 like
cjedgerton's avatar

I know this is old but here's what I did in 5.2 after running php artisan make:auth (A slight change since acsakshay's comment).

Added the following to the User.php class:

protected $table = 'members';

Updated the email key in the validator method of AuthController to return:

'email' => 'required|email|max:255|unique:members

That's it!

4 likes
randy_roberts's avatar

Found this after posting to a thread on extending Sentinel and have tried all the above with no success. Also found that registering a new user has the same error regarding no users table.

I have installed the latest Sentinel which comes with 5.1 Is it possible that 5.2 works with the above?

Thanks!

jeffz2016's avatar

@cjedgerton Good job - thanks for sharing.

A note for other people: I actually created a new model Member.

This required:

  1. in AuthController -> validator(array $data) 'email' => 'required|email|max:255|unique:members'

  2. in AuthController -> create(array $data) return Member::create([ ...

But actually, it takes quite a lot of tweaks to make entire login/register/password reminder for multiple users, if you want to keep Laravel native auth and all.

1 like
Lanka's avatar

How to use this in laravel 5.3

1 like

Please or to participate in this conversation.