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

Asked 8 years ago Modified 19 hours ago 3733 Views
0
Jiwan Thapa Post Date: Apr 03, 2018

Answers (1)

1

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.

Jiwan Thapa Answered: Apr 03, 2018
Comments

Sign in to help the community by answering this question.

Log In to Answer