Default when make feather Authentication is table User, and fields:
> name, email, password,...
A. When you want to custom table name, or field name??
Ex:
> table members, and fields: user_name, user_email, user_pass
1. Update table name on config/auth
2. At User modal: add or update:
protected $table = 'members'; | |
protected $fillable = [ | |
'user_name', 'user_email', 'user_pass', | |
]; | |
protected $hidden = [ | |
'user_pass', 'remember_token', | |
]; | |
public function username() | |
{ // column of User table which we are going use for login | |
return 'user_email'; | |
} | |
public function getAuthPassword() | |
{ | |
return $this->user_pass; | |
} |
2b. Also, at LoginController, add:
public function username() | |
{ // column of User table which we are going use for login | |
return 'user_email'; | |
} |
3. Update view blade file -> field form Login/Register:
Update attribute name, such as
<input id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="user_email" value="{{ old('email') }}" required autocomplete="email" autofocus> |
4. Update field name on validator, create method of RegisterController
5. Update table members that have field: remember_token, email_verified_at
B. When add mew field:
Do step 2,3,4 above same as any field.
Ref:
https://stackoverflow.com/questions/55626323/changing-laravel-auth-table-name-and-column-names
https://laracasts.com/discuss/channels/laravel/change-column-names-for-the-auth
https://viblo.asia/p/tao-authentication-rieng-de-check-dang-nhap-trong-laravel-63vKj0WVl2R
Nhận xét
Đăng nhận xét