How to change the Auth table name in Laravel?

By Laravel Developer

Infinitbility
1 min readNov 20, 2019

Hello guys,

Laravel Auth default table name is users but sometimes we need to change auth table name instead of users.

Simple solution,

Replace the Auth Model code to the below code.

<?phpnamespace App;use Illuminate\Contracts\Auth\MustVerifyEmail;use Illuminate\Foundation\Auth\User as Authenticatable;use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{use Notifiable;/** * The attributes that are mass assignable. * * @var array */protected $fillable = [ 'name', 'email', 'password',
];
/** * The attributes that should be hidden for arrays. * * @var array */protected $hidden = [ 'password', 'remember_token',];/** * The attributes that should be cast to native types. * * @var array */
protected $casts = [ 'email_verified_at' => 'datetime',];/** * The table associated with the model. * * @var string */protected $table = 'You view / table name'; // add this line with your table name}

Note: Replace Your table/view name

Happy Coding……

--

--

Infinitbility
Infinitbility

Written by Infinitbility

Subscribe my newsletter to get weekly updates. — https://infinitbility.com/about

No responses yet