Laravel 5.5 - Login With Only Mobile Number Using Laravel Custom Auth


Today, we are share with you how to modify laravel bydefault authentication and make it custom as per our requirement. in this totorials we are modify laravel authentication sysstem and make "how to login with only mobile number in laravel application using laravel custom authentication". but you also can modify as per your requirement.

Laravel provide bydefault authentication system on users table's email and password fields and it very helpfull for us. but sometime we want to change laravel authentication and make is as per our requirment. Ex. we want username or password, we want mobile number and password and sometime we want only mobile number for authentication and not extra needed. so, how to built laravel custom authentication? we are share here with very simple example. if you fallow all step then you can change laravel auth and set your custom auth as per your choice. it is very easy.

Create Laravel New Project

First, we are create one new fresh laravel project run by following command. if you already have laravel project and you want implement custom auth your exist laravel application. so, this step skeep and move on next.

composer create-project --prefer-dist laravel/laravel blog

After installation please setup your database in .env file

Create Laravel Auth

Next, Generate laravel bydefault auth run by following command

php artisan make:auth

Run Laravel Migration

Befor run laravel migration please add one extra mobile_no field in user table migration open it and add like that.

Schema::create('users', function (Blueprint $table) {

Next, then after run laravel migration using following command

php artisan migrate

Change in RedirectIfAuthenticated

Next, now we are need some changes in RedirectIfAuthenticated middleware. so, open your app/Http/Middleware/RedirectIfAuthenticated.php file and make change like that.

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class RedirectIfAuthenticated
     * Handle an incoming request.
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string|null  $guard
     * @return mixed
    public function handle($request, Closure $next, $guard = null)
        if (Auth::check()) {
            return redirect('/home');

        return $next($request);


Overwrite login() method

Next, we are need to overwrite login() method. so, open your app/Http/Controllers/Auth/LoginController.php file and make some change following way.

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\User;

class LoginController extends Controller
    | Login Controller
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.

    use AuthenticatesUsers;

     * Where to redirect users after login.
     * @var string
    protected $redirectTo = '/home';

     * Create a new controller instance.
     * @return void
    public function __construct()
        $this->user = new User;

    public function login(Request $request)
        // Check validation
        $this->validate($request, [
            'mobile_no' => 'required|regex:/[0-9]{10}/|digits:10',            

        // Get user record
        $user = User::where('mobile_no', $request->get('mobile_no'))->first();

        // Check Condition Mobile No. Found or Not
        if($request->get('mobile_no') != $user->mobile_no) {
            \Session::put('errors', 'Your mobile number not match in our system..!!');
            return back();
        // Set Auth Details
        // Redirect home page
        return redirect()->route('home');
Change In Login Blade

Next, open your resources/views/auth/login.blade.php file and make changes this way.


<div class="container">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <div class="panel panel-default">
                <div class="panel-heading">Login</div>

                <div class="panel-body">
                    <form class="form-horizontal" method="POST" action="{{ route('login') }}">
                        {{ csrf_field() }}
                        <div class="form-group{{ $errors->has('mobile_no') ? ' has-error' : '' }}">
                            <label for="mobile_no" class="col-md-4 control-label">Enter Mobile No.</label>
                            <div class="col-md-6">
                                <input id="mobile_no" type="text" class="form-control" name="mobile_no" value="{{ old('mobile_no') }}" required autofocus>
                                @if ($errors->has('mobile_no'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('mobile_no') }}</strong>

                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-4">
                                <div class="checkbox">
                                        <input type="checkbox" name="remember" {{ old('remember') ? 'checked' : '' }}> Remember Me

                        <div class="form-group">
                            <div class="col-md-8 col-md-offset-4">
                                <button type="submit" class="btn btn-primary">

                                <a class="btn btn-link" href="{{ route('password.request') }}">
                                    Forgot Your Password?

Now we are ready to run our example so run bellow command ro quick run:

php artisan serve

Now you can open bellow URL on your browser:


If you want to any problem then please write comment and also suggest for new topic for make tutorials in future. Thanks...