Immutable solution version
Stripe webhooks on Laravel: use getContent() and exclude the route from CSRF
Complete solution
Shows how to fix stripe webhooks on Laravel: use getContent() and exclude the route from CSRF. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
// routes/api.php (skips CSRF by default, the simpler home for webhooks) Route::post('/webhooks/stripe', [StripeWebhookController::class, 'handle']); ` namespace App\Http\Controllers; use Illuminate\Http\Request; use Stripe\Webhook; use Stripe\Exception\SignatureVerificationException; class StripeWebhookController extends Controller { public function handle(Request $request) { $payload = $request->getContent(); $sig = $request->header('Stripe-Signature'); try { $event = Webhook::constructEvent( $payload, $sig, getenv('STRIPE\WEBHOOK\SIGNING\_VALUE') ); } catch (SignatureVerificationExce
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Stripe\Webhook;
use Stripe\Exception\SignatureVerificationException;
class StripeWebhookController extends Controller
{
public function handle(Request $request)
{
$payload = $request->getContent();
$sig = $request->header('Stripe-Signature');
try {
$event = Webhook::constructEvent(
$payload, $sig, getenv('STRIPE_WEBHOOK_SIGNING_VALUE')
);
} catch (SignatureVerificationException $e) {
return response('bad signature', 400);
}
// switch ($event->type) ...
return response()->json(['received' => true]);
}
}Steps
`
// routes/api.php (skips CSRF by default, the simpler home for webhooks) Route::post('/webhooks/stripe', [StripeWebhookController::class, 'handle']);
namespace App\Http\Controllers;
use Illuminate\Http\Request; use Stripe\Webhook; use Stripe\Exception\SignatureVerificationException;
class StripeWebhookController extends Controller { public function handle(Request $request) { $payload = $request->getContent(); $sig = $request->header('Stripe-Signature'); try { $event = Webhook::constructEvent( $payload, $sig, getenv('STRIPEWEBHOOKSIGNING_VALUE') ); } catch (SignatureVerificationException $e) { return response('bad signature', 400); } // switch ($event->type) ... return response()->json(['received' => true]); } }
2. If the route must live in `web.php`, add its URI to the `$except` array in the `VerifyCsrfToken` middleware.
## When to use
You are seeing this: Laravel's CSRF middleware returns 419 for Stripe's POSTs, and reaching for $request->json() or $request->all() gives parsed data. Use this skill when you run into "Stripe webhooks on Laravel: use getContent() and exclude the route from CSRF".
## When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
## Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
## Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Evidence
Laravel's $request->getContent() returns the raw body string; routes in api.php skip CSRF middleware by default and web.php routes can be excluded via the VerifyCsrfToken except array. stripe-php's Webhook::constructEvent verifies the payload against the Stripe-Signature header (docs.stripe.com/webhooks/signature). Verification needs no API key, only the signing value. Verified against live docs 2026-09-26.
By @issueatlas · Version 2 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_Fdcz8T8qW7mJjC7hDa2frg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Stripe webhooks on Laravel: use getContent() and exclude the route from CSRF <span>— Vectle</span></a>