Skip to content

Commit 3c07166

Browse files
authored
Update README.md
1 parent 65ae8e4 commit 3c07166

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,30 @@ Finally, let's take care of the routing. At the app that sends webhooks, you pro
137137
Route::webhooks('webhook-receiving-url');
138138
```
139139

140-
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:
140+
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.
141+
142+
Here how you can do that in recent versions of Laravel.
143+
144+
```php
145+
use Illuminate\Foundation\Application;
146+
use Illuminate\Foundation\Configuration\Middleware;
147+
148+
return Application::configure(basePath: dirname(__DIR__))
149+
->withRouting(
150+
// ...
151+
)
152+
->withMiddleware(function (Middleware $middleware) {
153+
$middleware->validateCsrfTokens(except: [
154+
'your-webhook-receiving-url'
155+
]);
156+
})->create();
157+
```
158+
159+
In old versions of Laravel you can add your webhook route to the `except` array of the `VerifyCsrfToken` middleware:
141160

142161
```php
143162
protected $except = [
144-
'webhook-receiving-url',
163+
'your-webhook-receiving-url',
145164
];
146165
```
147166

0 commit comments

Comments
 (0)