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

Asked by Anonymous on 03 Apr 2018 2052 Views

Anonymous on 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> 

Now you can login with your username.

You must be logged in to answer a question. or