Laravel Authenticate Login and Logout Functions

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Validation\ValidationException;
  1. Login Function.
public function login(Request $request)

if (method_exists($this, 'hasTooManyLoginAttempts') && $this->hasTooManyLoginAttempts($request)) {
$seconds = $this->limiter()->availableIn(
return throw ValidationException::withMessages([
$this->username() => [trans('auth.throttle', [
'seconds' => $seconds,
'minutes' => ceil($seconds / 60),

if ($this->attemptLogin($request)) {

if ($response = $this->authenticated($request, $this->guard()->user())) {
return $response;
return $request->wantsJson() ? new JsonResponse([], 204) : redirect()->route('/');


return throw ValidationException::withMessages([
$this->username() => [trans('auth.failed')],

public function logout(Request $request)
if ($response = $this->loggedOut($request)) {
return $response;

return $request->wantsJson() ? new JsonResponse([], 204) : redirect()->to('');




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Fetching a Trip Down Memory Lane — JS

A Tinder Progressive Web App Performance Case Study

API Authentication with Phoenix and React — part 2

How to use React with Symfony 4

CRUD operations with Express.js (Node Js framework), MongoDB & Mongoose

Making user journeys configurable in the GOV prototype kit

•seduzione• Disponibile/Available . . . #tattoo #blackwork #dotwork #blacktattoo…

Short form with a bold first sentence can’t be clicked

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Shah Md. Iktakhairul Islam

Shah Md. Iktakhairul Islam

More from Medium

How To Use Factory States In Laravel 8

Integrate google reCAPTCHA enterprise with laravel and vue -Part 01

Setting 🆙 Cloudflare Email fo

How To Install Laravel ?