Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze authored Jan 20, 2025
1 parent 65ae8e4 commit 3c07166
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,30 @@ Finally, let's take care of the routing. At the app that sends webhooks, you pro
Route::webhooks('webhook-receiving-url');
```

Behind the scenes, by default this will register a `POST` route to a controller provided by this package. Because the app that sends webhooks to you has no way of getting a csrf-token, you must add that route to the `except` array of the `VerifyCsrfToken` middleware:
Behind the scenes, by default this will register a `POST` route to a controller provided by this package. Because the app that sends webhooks to you has no way of getting a csrf-token, you must exclude the route from csrf token validation.

Here how you can do that in recent versions of Laravel.

```php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Middleware;

return Application::configure(basePath: dirname(__DIR__))
->withRouting(
// ...
)
->withMiddleware(function (Middleware $middleware) {
$middleware->validateCsrfTokens(except: [
'your-webhook-receiving-url'
]);
})->create();
```

In old versions of Laravel you can add your webhook route to the `except` array of the `VerifyCsrfToken` middleware:

```php
protected $except = [
'webhook-receiving-url',
'your-webhook-receiving-url',
];
```

Expand Down

0 comments on commit 3c07166

Please sign in to comment.