Jiwan Thapa
03 Apr, 2018

How Can I Login In Laravel Using The Username In Place Of Email Address?

1 Answer         2739 Views

Jiwan Thapa
03 Apr, 2018

Go to Vendor\laravel\framework\src\Illuminate\Foundation\Auth\AuthenticatesUsers.php

Search for the method username and return name instead of email

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

Change the login field in login page to allow username as input value.

 
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}"> 
    <label for="name" class="col-md-4 control-label">Username</label> 
    <div class="col-md-6"> 
        <input id="name" type="name" class="form-control" name="name" value="{{ old('name') }}" required autofocus> 
        @if ($errors->has('name')) 
            <span class="help-block"> 
                <strong>{{ $errors->first('name') }}</strong> 
            </span> 
        @endif 
    </div> 
</div>  

Now you can login with your username.


25 Likes         0 Dislike         0 Comment        


Leave a comment