Laravel 8 Auth Login with Username or Email

Laravel 8 Auth Login with Username or Email

Hello friends, today we will show how to login with username or email in laravel 8 auth. Here you will learn laravel 8 login with username or email in authentication. we will explain how to make auth login with username and email address in laravel 8 application. we will show laravel 8 login with username or email.

Example

public function login(Request $request)
    {   
        $input = $request->all();
  
        $this->validate($request, [
            'username' => 'required',
            'password' => 'required',
        ]);
  
        $fieldType = filter_var($request->username, FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
        if(auth()->attempt(array($fieldType => $input['username'], 'password' => $input['password'])))
        {
            return redirect()->route('home');
        }else{
            return redirect()->route('login')
                ->with('error','Email-Address And Password Are Wrong.');
        }
          
    }

I hope you understand of laravel 8 auth login with username or email and it can help you…

Read Also :  Laravel 8 cURL HTTP Request Example