<?php
namespace App\Http\Middleware;
use Closure;use Illuminate\Http\Request;use Symfony\Component\HttpFoundation\Response;
class RequireIdempotencyKey {public function handle(Request $r,Closure $next):Response{$key=$r->header('Idempotency-Key');if(!$key || !preg_match('/^[A-Za-z0-9._:-]{8,64}$/',$key))return response()->json(['error'=>['code'=>'IDEMPOTENCY_KEY_REQUIRED','message'=>'A valid Idempotency-Key header is required.']],422);return $next($r);}}
