Middleware provide a convenient mechanism for filtering HTTP requests entering your application. More about them here.
You can enable and disable Middlewares as you wish.
There are two types of Middlewares, General (applied on all the Routes by default) and Endpoints Middlewares (applied on some Endpoints).
The Middlewares CAN be placed in Ship layer or Container layer depending on its roles.
If a Middleware is written inside a Container it MUST be registered inside that Container.
To register Middlewares in a Container the container needs to have a
MiddlewareServiceProvider, and like all other Container Providers it MUST be registered in the
MainServiceProviderof that Container.
General Middlewares (like some default Laravel Middlewares) SHOULD live in the Ship layer
app/Ship/Middlewares/*and are registered in the Ship Main Provider.
Third Party packages Middleware CAN be registered in Containers or on the Ship layer (wherever they make more sense). Example: the
jwt.authmiddleware "provided by the JWT package" is registered in the Authentication Container (
Middleware registration inside the Container Example:
Middleware registration inside the Ship layer (HTTP Kernel) Example: