Skip to main content
Back to packages
1,185 GitHub stars

spatie/laravel-webhook-client

View on GitHub

Description

Receive webhooks in Laravel apps

At the app that sends webhooks, you probably configure an URL where you want your webhook requests to be sent. In the routes file of your app, you must pass that route to Route::webhooks. Here's an example:

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 exclude the route from csrf token validation.

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

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();