Download the PHP package laniakea/middleware-priority without Composer
On this page you can find all versions of the php package laniakea/middleware-priority. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download laniakea/middleware-priority
More information about laniakea/middleware-priority
Files in laniakea/middleware-priority
Package middleware-priority
Short Description More flexible way to manage Laravel's HTTP middleware priority.
License MIT
Homepage https://github.com/tzurbaev/laravel-middleware-priority
Informations about the package middleware-priority
Middleware priority manager for Laravel 11+
This package provides more flexible way to manage HTTP middleware priority in Laravel 11+ applications.
Please note that this package only compatible with fresh Laravel 11+ applications (or applications that have been upgraded to Laravel 11+ with new directory structure / application bootstrapping).
You can simply append/prepend your middleware to the priority list or do more complex things, such as:
- Add your middleware before or after specific middleware;
- Swap positions of two middleware;
- Remove middleware from the priority list.
This package provides default Laravel's priority list (latest update: Laravel 11.0.7; check DefaultMiddlewarePriority
class),
so you can use it as a base for your custom priority list.
Installation
You can install the package via composer:
Usage
This package is intended to be used with Laravel's Application::configure()
builder (located in bootstrap/app.php
file).
Create priority manager
Create new instance of Laniakea\MiddlewarePriority\MiddlewarePriorityManager
inside withMiddleware
callback
to start using middleware priority manager. Please note that the priority list will be empty by default
(unless you mutated it before creating manager instance).
Use Laravel's default priority
If you want to use Laravel's default priority list, you can use static MiddlewarePriorityManager::withDefaults
method
to create manager instance with default priority list.
Second argument to the withDefaults()
method accepts user-defined list of default middleware priority (if it's null
or was not passed, default Laravel's priority list will be used).
Appending middleware
Here and below it's assumed that manager created & used inside the
withMiddleware
callback.
Use append(string|array $middleware)
method to append middleware to the priority list.
Prepending middleware
Use prepend(string|array $middleware)
method to prepend middleware to the priority list.
Add middleware before specific middleware
Use before(string $middleware, string|array $newMiddleware)
method to add middleware before specific middleware.
Also you can use array of middleware as a second argument. In this case new middleware will be added according to the order in the array.
Add middleware after specific middleware
Use after(string $middleware, string|array $newMiddleware)
method to add middleware after specific middleware.
Also you can use array of middleware as a second argument. In this case new middleware will be added according to the order in the array.
Swap middleware positions
Use swap(string $what, string $with)
method to swap positions of two middleware.
Remove middleware
Use remove(string|array $what)
method to remove middleware from the priority list.
Also you can use array of middleware. All listed middleware will be removed from the priority list.
After removing middleware from the priority list, it's position will be determined by the order of registration in the group middleware. See example below.
Get current priority list
If you need to retrieve current priority list, you can use getPriority()
method.
Complete example
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
- Timur Zurbaev
- All Contributors
License
The MIT License (MIT). Please see License File for more information.