1

Laravel Framework 5.6.38

I am trying to change the default username auth check from 'email' to 'id', So i put the username() method inside User model file to override the default username method

<?php namespace App; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use Notifiable; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'email', 'password','id' ]; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; public function username() { return 'id'; } } 

It's not working with me . unless i change it from laravel vendor file Illuminate\Foundation\Auth\AuthenticatesUsers.php

 /** * Get the login username to be used by the controller. * * @return string */ public function username() { return 'kocid'; } 

The login now working but when i run composer update , the file return to it default, so i need a solution to successfully override this method using User model.

2 Answers 2

2

According to the documentation, https://laravel.com/docs/5.6/authentication#authentication-quickstart...you should do that in your LoginController

public function username() { return 'id'; } 
Sign up to request clarification or add additional context in comments.

Comments

0

Add the username method to your LoginController to override the method from the AuthenticatesUsers trait (Docs - Username Customization).

public function username() { return 'id'; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.