Member-only story

Authenticate Routes In Laravel 8 Using Middleware

Bipsmedium
2 min readApr 12, 2021

--

In this tutorial, we will learn about Middleware and how to authenticate routes in Laravel 8 using Middleware.

What is Middleware

  • Middleware is like a tool or a way used for security reasons in any application made with Laravel. It checks all the HTTP requests (GET or POST) that comes from the users and starts the verification.
  • If the user is not verified then the middleware will redirect that user to the login page of that application else the middleware will allow the user to proceed in the application.

How to assign a Middleware to a specific route

Before assigning a Middleware for a particular route, we have to provide a class for that Middleware with the help of a key.

By default Laravel has provided all the required classes of Middleware in $routeMiddleware property inside App\Http\Kernal.php. as shown below

protected $routeMiddleware = [

'auth' => \Illuminate\Auth\Middleware\Authenticate::class,

'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,

'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,

--

--

Bipsmedium
Bipsmedium

Written by Bipsmedium

Hi, This is Biplab and I am a PHP laravel developer and other open source technologies. I am here to share my experience with the community.

No responses yet