Last active
July 23, 2024 07:16
-
-
Save erdum/38bf163a078500b5483b0417cb11eab1 to your computer and use it in GitHub Desktop.
Assign Requests ID Middleware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
use Illuminate\Http\Request; | |
use Symfony\Component\HttpFoundation\Response; | |
class AssignRequestId | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next | |
*/ | |
public function handle(Request $request, Closure $next): Response | |
{ | |
$request->headers->set('Request-Id', str()->random(20)); | |
return $next($request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment