softonic/laravel-middleware-request-id

Middleware for Laravel Framework to add the X-Request-ID header in the requests and responses.
112,456 15
Install
composer require softonic/laravel-middleware-request-id
Latest Version:3.0.1
PHP:>=8.5
Laravel:12
Older releases:5 · 7 · 8
License:Apache-2.0
Last Updated:Jan 13, 2026
Links: GitHub  ·  Packagist
Maintainer: Joskfg

softonic/laravel-middleware-request-id

Build Status

Requirements

  • PHP >= 8.5
  • Laravel 12.x

Install

$ composer require softonic/laravel-middleware-request-id

Usage

For all routes or a specific group

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' => [
            ...
        ],
    ];

For a specific route

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');

Extra

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.

Testing

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

Related Packages

nmehroj/route-usage-tracker

Laravel Route Usage Tracker Package with Vue.js 3 Dashboard and Inertia.js Suppo...

7 0
irazasyed/laravel-gamp

Send analytics data to Google Analytics from Laravel. A package for GA Measureme...

1,614,517 331
barryvdh/laravel-stack-middleware

Stack Middleware for Laravel 5

430,412 41
stevenmaguire/laravel-middleware-csp

Provides support for enforcing Content Security Policy with headers in Laravel r...

107,787 39

Version History

Version Released PHP Laravel License
3.0.1 >=8.5 ^12.0 Apache-2.0
3.0.0 >=8.5 ^12.0 Apache-2.0
v2.1.0 >=7.4 >7.0 Apache-2.0
v2.0.0 >=7.4 >7.0 Apache-2.0
v1.0.1 >=7.0 ^5.3 Apache-2.0