barryvdh/laravel-stack-middleware
Adds a simple stack-style middleware manager for Laravel, letting you group, push, and compose middleware in a defined order. Useful for building reusable request/response pipelines and applying them to routes or controllers with minimal boilerplate.
auth + throttle for API routes).Kernel.php or config files.spatie/laravel-permission), making it versatile for most use cases.Kernel.php, requiring no database changes or external dependencies. Minimal risk of breaking existing workflows.HttpTests, Middleware facades), reducing integration risk.Kernel.php or config files), easing maintenance and reducing merge conflicts.composer.json (e.g., ^12.0).auth after CORS) could break request flows.tenant-{id}-stack, feature-{flag}-stack)?auth, throttle, and validation stacks.tenant-1-auth-stack).experimental-feature-stack).composer require barryvdh/laravel-stack-middleware
app/Http/Kernel.php:
protected $middlewareGroups = [
'web' => [
\Barryvdh\StackMiddleware\Middleware\StackMiddleware::class,
// Other middleware...
],
];
middleware helper or facade to apply stacks:
Route::middleware(['stack:auth'])->group(function () {
// Routes using the 'auth' stack
});
use Barryvdh\StackMiddleware\Facades\StackMiddleware;
$stack = StackMiddleware::stack('auth')->merge('cors');
Kernel.php and route files.auth, api, admin).api.stack) in a non-critical module.Kernel.php to include the StackMiddleware provider.README.md for reference.spatie/laravel-permission, fruitcake/laravel-cors).auth before role) are respected in stack order.Kernel.php → Write tests → Deploy to staging → Monitor → Roll out to production.Kernel.php to pre-migration state if issues arise.composer update and test in staging before production.config/middleware.php) for easier updates.README.md or wiki.fruitcake/laravel-pie) to visualize middleware execution.How can I help you explore Laravel packages today?