Skip to content

Commit b30d6f7

Browse files
authored
Update README.md
Add installation instructions for Laravel 11
1 parent 9e4128a commit b30d6f7

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,28 @@ composer require bilfeldt/laravel-correlation-id
3030
### Assigning Correlation ID to requests
3131

3232
> [!NOTE]
33-
> Ideally, the unique Correlation ID should be created at the **very first touch point** of your infrastructure like the initial server which could be a load balancer
33+
> Ideally, the unique Correlation ID should be created at the **very first touch point** of your infrastructure like the initial server which could be a load balancer.
3434
35-
As it can be tricky to create _Correlation ID_ on the server level and this is so easy in Laravel using middleware. This package provides a middleware for creating a _Correlation ID_ and attaching it to the request as a header `Correlation-ID` and to the response header as well. You should either assign the correlation id on the first touch point of your infrastructure or register the `CorrelationIdMiddleware` middleware globally as the first middleware in the `$middleware` property of your `app/Http/Kernel.php` class:
35+
As it can be tricky to create _Correlation ID_ on the server level (I do accept a PR with suggestions on how to do this in Nginx 😃) and this is so easy in Laravel using middleware. This package provides a middleware for creating a _Correlation ID_ and attaching it to the request as a header `Correlation-ID` and to the response header as well. You should assign the correlation id using a global middleware pushed as the first middleware to be applied.
36+
37+
#### Laravel 11
38+
39+
Registering a global middleware in Laravel 11 is done in the `bootstrap/app.php` file:
40+
41+
```php
42+
// bootstrap/app.php
43+
44+
use App\Http\Middleware\EnsureTokenIsValid;
45+
use Bilfeldt\CorrelationId\Middleware\CorrelationIdMiddleware
46+
47+
->withMiddleware(function (Middleware $middleware) {
48+
$middleware->prepend(CorrelationIdMiddleware::class);
49+
})
50+
```
51+
52+
#### Laravel 10 and below
53+
54+
In Laravel 10 and below then a global middleware is added in the `$middleware` property in `app/Http/Kernel.php`:
3655

3756
```php
3857
// app/Http/Kernel.php

0 commit comments

Comments
 (0)