1.

Explain middleware in laravel.

Answer»

MIDDLEWARE provides a MECHANISM to filter HTTP request, entering your application. Basic middleware can be explained with authentication. Laravel includes middleware for authentication.  if a user is unauthenticated then we want to redirect to the login page and if it’s authenticated then we will allow proceeding further action. This can be easily done with middleware.

php artisan make:middleware middleware_name  is the artisan command to define a new middleware in your application. By default, all middleware will be stored in app/Http/Middleware directory.  To run middleware during every HTTP request to your application, you can list the middleware class in the $middleware property of your app/Http/Kernel.php class. To ASSIGN middleware to specific routes assign it in key-value pair at app/Http/Kernel.php class $routeMiddleware property.



Discussion

No Comment Found