Skip to main content
Back to packages
1,189 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();

Recent Courses on Laravel Daily

Roles and Permissions in Laravel 13

14 lessons
57 min

Testing in Laravel 13 For Beginners

26 lessons
1 h 41 min read

Queues in Laravel 13

18 lessons
1 h 12 min read