Laravel 5.2 users user table with automatic replacement

I used a new function in Laravel:

php artisan make:auth 

But when I register, the users database table will be used by default, but I want to change it to another table. And by default it uses updated_at and created_at in this table, I also want to delete this.

Auth / AuthController

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

\ User application

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

This is what I thought would have changed him, but they did not. I hope someone can tell me more about this issue.

+6
source share
4 answers

To change the name of the table, go to app/User.php and set the $table property to user, for example:

 $table = 'new_table'; 

You must also change the default migration. Go to: /database/migrations/2014_10_12_000000_create_users_table.php file and change users here to one name. To remove timestamps, you can delete the line:

 $table->timestamps(); 

however, if I were you, I would reconsider deleting these timestamps

+7
source

DON'T FORGET TO CHANGE VALIDATION IN THE .PHP REGISTRATION ROLLER AS GOOD.

from

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

to

 'email' => 'required|email|max:255|unique:company', 
+5
source

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

 protected $table = 'auth_users'; 

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

+2
source

Check Laravel 5.3 Change the user table in Auth for an alternative solution, using the modification in config / auth.php and RegisterController.php.

To disable timestamps, which you can also use in the model class:

 public $timestamps = false; 
0
source

All Articles