Laravel & Php

Laravel Login with username, email or phone


How to login with user name, email or phone number

<?php

namespace AppHttpControllersAuth;
use IlluminateHttpRequest;
use AppHttpControllersController;
use IlluminateFoundationAuthAuthenticatesUsers;

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 = '/dashboard';

   protected function credentials(Request $request){
      if(is_numeric($request->get('email'))){
         return ['phone'=>$request->get('email'),'password'=>$request->get('password')];
      }
      elseif (filter_var($request->get('email'), FILTER_VALIDATE_EMAIL)) {
         return ['email' => $request->get('email'), 'password'=>$request->get('password')];
      }
      return ['username' => $request->get('email'), 'password'=>$request->get('password')];
   }

   /**
   * Create a new controller instance.
   *
   * @return void
   */
   public function __construct()
   {
   $this->middleware('guest')->except('logout');
   }
}

Laravel
Share with Friends

Like this chef? Share with friends..