Middleware for Laravel Framework to add the X-Request-ID header in the requests and responses.
softonic/laravel-middleware-request-id is a Laravel package for middleware for laravel framework to add the x-request-id header in the requests and responses..
It currently has 15 GitHub stars and 108.788 downloads on Packagist (latest version 3.0.1).
Install it with composer require softonic/laravel-middleware-request-id.
Discover more Laravel packages by softonic
or browse all Laravel packages to compare alternatives.
Last updated
$ composer require softonic/laravel-middleware-request-id
Add Softonic\Laravel\Middleware\RequestId::class in App\Http\Kernel.
For all routes:
protected $middleware = [
\Softonic\Laravel\Middleware\RequestId::class,
....
]
Specific group:
// Example for WEB group
protected $middlewareGroups = [
'web' => [
\Softonic\Laravel\Middleware\RequestId::class,
...
],
'api' => [
...
],
];
Register the middleware as a route middleware in App\Http\Kernel.
protected $routeMiddleware = [
...
'request-id' => Softonic\Laravel\Middleware\RequestId::class,
];
then, use it in your routes file, for example in routes\web.php
Route::get('route', function() {})->middleware('request-id');
If you need to have the X-Request-Id ASAP, you can modify \App\Providers\AppServiceProvider::boot adding $_SERVER['HTTP_X_REQUEST_ID'] ??= \Ramsey\Uuid\Uuid::uuid4()->toString();.
This is going to allow you to use the X-Request-ID in the framework booting to for example customize monolog or in console executions.
To run the tests:
docker compose run --rm test
To run PHPUnit only:
docker compose run --rm phpunit
To check code style:
docker compose run --rm php composer run phpcs
To fix code style issues:
docker compose run --rm fixcs
To run static analysis:
docker compose run --rm php composer run phpstan