Search

Laravel Artisan Generator Command: The make:middleware Command

December 7, 2016 —John Koster

The make:middleware command is used to generate a middleware class. It accepts a name that will be used as the name of the newly generated class and file. Generated classes are stored within the app/Http/Middleware directory.

The following example would create a new middleware file in the app/Http/Middleware/MyMiddleware.php file:

1# Generate a new middleware class.
2php artisan make:middleware MyMiddleware

This command will not overwrite any existing middleware classes that have the same name. An error stating Middleware already exists! will be displayed instead.

The make:middleware command is also capable of generated namespaced classes. Accomplish this by separating namespace sections using the \ when supplying the middleware name. A nested directory will be created and the correct namespace will be set on the generated class.

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.