Hi guys, we all know how to to add middlewares in the kernel, but what if we want to add middleware only under certain conditions. So, in this quick tip, i’ll show you how to add dynamic middleware in laravel.

In this example, i want to activate middleware only if debug mode is true. ( we can achieve this example differently, but it’s just example ).

Open your App\Providers\AppServiceProvider.php file and put the following code :

that’s it, i hope this is useful for you :).

Read Also  Force https redirect in Laravel

No Comments

Leave a Reply

your email address will not be published. required fields are marked *