Larvel Cartalyst Sentinel - Adding a username column to a user table (which is the right way)

I pulled into cartalyst / sentinel and I performed the migration needed to generate the tables.

php artisan migrate --package=cartalyst/sentinel 

I noticed that these are the columns available in the users table

  • ID
  • Email
  • password
  • permissions
  • last_login
  • first_name
  • last_name
  • created_at
  • updated_at

I want to add a username after the letter. So I created a migration file that does this.

 //add a column username after email in the users table $table->string('username')->after('email')->unique(); 

Now when I use Sentinel :: register

 $credentials = Input::all(); $user = Sentinel::register($credentials); 

The username is not saved in the table. Thus, I managed to get it populated by editing vendor / cartalyst / sentinel / src / Users / EloquentUser.php

 protected $fillable = [ 'email', 'username', /* i added this */ 'password', 'last_name', 'first_name', 'permissions', ]; 

Now it works, the username is saved in the table. But im wondering if i am doing the right thing? Do not touch files in the package folder. How do we solve this?

+6
source share
2 answers

Nearly. You must create your own user clans by expanding vendor/cartalyst/sentinel/src/Users/EloquentUser.php :

 use Cartalyst\Sentinel\Users\EloquentUser as CartalystUser; class User extends CartalystUser { protected $fillable = [ 'email', 'username', /* i added this */ 'password', 'last_name', 'first_name', 'permissions', ]; } 

Publish Sentinel configuration:

 php artisan config:publish cartalyst/sentinel 

And in the configuration file, install the user model yourself:

 'users' => [ 'model' => 'Your\Namespace\User', ], 
+12
source

In Laravel 5.2, after following @Antonio steps, you need to run php artisan config:cache instead of php artisan config:publish cartalyst/sentinel

+3
source

Source: https://habr.com/ru/post/976087/


All Articles