Skip to content

Instantly share code, notes, and snippets.

@erdum
Last active July 23, 2024 07:16
Show Gist options
  • Save erdum/38bf163a078500b5483b0417cb11eab1 to your computer and use it in GitHub Desktop.
Save erdum/38bf163a078500b5483b0417cb11eab1 to your computer and use it in GitHub Desktop.
Assign Requests ID Middleware
<?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