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
Laravel 13 Starter Kit Teams and Customizations
10 lessons
33 min
Queues in Laravel 13
18 lessons
1 h 12 min read
How to Structure Laravel 13 Projects
16 lessons
1 h 32 min read