Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.2 auth change 'users' table

I used the new feature in Laravel:

 php artisan make:auth

But when I register it will use the database table users by default, but I want to change that to an other table. And by default it uses updated_at and created_at in that table, I want to remove that too.

Auth/AuthController

protected function create(array $data)
{
    return User::create([
        'voornaam' => $data['voornaam'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
    ]);
}

app\User

protected $fillable = [
    'voornaam', 'email', 'password',
];

This are the things I thought would change it, but they didn't. I hope somebody can tell me some more about this issue.

like image 737
Draity Avatar asked Jan 07 '16 20:01

Draity


3 Answers

To change table name go to app/User.php and set property $table to custom one for example:

$table = 'new_table';

You should also change default migration. Go to: /database/migrations/2014_10_12_000000_create_users_table.php file and change users here for the same name. To remove timestamps you can remove line:

$table->timestamps();

however if I were you I would reconsider removing those timestamps

like image 153
Marcin Nabiałek Avatar answered Oct 20 '22 08:10

Marcin Nabiałek


DO NOT FORGET TO CHANGE VALIDATION IN REGISTERCONTOLLER.PHP AS WELL.

from

'email' => 'required|email|max:255|unique:users',

to

'email' => 'required|email|max:255|unique:company',
like image 27
Elnur Ibrahim-zade Avatar answered Oct 20 '22 07:10

Elnur Ibrahim-zade


By default model take its class name as table name !
I define a protected property at the top of App/User.php

protected $table = 'auth_users';

This tells laravel to use auth_users table instead of default user table. and it works like charm.

like image 44
Abdul Manan Avatar answered Oct 20 '22 06:10

Abdul Manan