https://github.com/softonic/laravel-middleware-request-id
https://github.com/softonic/laravel-middleware-request-id
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/softonic/laravel-middleware-request-id
- Owner: softonic
- License: other
- Created: 2017-02-07T10:31:04.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-06-28T14:59:46.000Z (almost 5 years ago)
- Last Synced: 2025-03-24T19:39:47.417Z (about 1 year ago)
- Language: PHP
- Size: 6.84 KB
- Stars: 15
- Watchers: 7
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# softonic/laravel-middleware-request-id
[](https://travis-ci.org/softonic/laravel-middleware-request-id)
## Install
```bash
$ 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:
```php
protected $middleware = [
\Softonic\Laravel\Middleware\RequestId::class,
....
]
```
Specific group:
```php
// 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`.
```php
protected $routeMiddleware = [
...
'request-id' => Softonic\Laravel\Middleware\RequestId::class,
];
```
then, use it in your routes file, for example in `routes\web.php`
```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.