Explain how to create custom middleware in laravel?



Explain how to create custom middleware in laravel?..

Answer / Prashant Kashandhan

To create a custom middleware in Laravel, follow these steps:
1. Create a new middleware by running `make:middleware YourMiddlewareName`.
2. Implement the `Handle` contract or extend the base middleware class `IlluminateHttpMiddlewareKernel`.
3. Define the `handle` method to execute your custom logic.
4. Register the middleware in the `app/Http/Kernel.php` file by adding it to the appropriate HTTP kernel's $routeMiddleware array.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Laravel PHP Framework Interview Questions

How to access session data?

1 Answers  


What is faker in laravel?

1 Answers  


What are the advantages of queue?

1 Answers  


What is x-xsrf-token?

1 Answers  


What is the use of accessors and mutators in eloquent?

1 Answers  


What is mvc laravel?

1 Answers  


What is laravel 5?

1 Answers  


What the server requirements for laravel?

1 Answers  


What do you know about laravel contracts?

1 Answers  


What is escaping a string?

1 Answers  


Explain fluent query builder in laravel.

1 Answers  


How to create route name in laravel 5?

1 Answers  


Categories