A comprehensive webhook management package for Laravel applications. Easily manage, track, and process incoming webhooks with built-in support for workspace and project scoping.
- Webhook Management: Complete CRUD operations for webhooks.
- Secure Ingress: Automatic token generation for secure, unique webhook endpoints.
- Event Tracking: Logs all incoming webhook payloads, headers, and processing status.
- Scoped by Default: Built-in support for User, Workspace, and Project scoping.
- Flexible Integration: Seamlessly integrates with other WhileSmart packages like
eloquent-workspaces,projects, andactivities. - API Ready: Comes with pre-configured controllers and routes for rapid development.
You can install the package via composer:
composer require whilesmart/eloquent-webhooksYou should publish and run the migrations with:
php artisan vendor:publish --tag="webhooks-migrations"
php artisan migrateYou can publish the config file with:
php artisan vendor:publish --tag="webhooks-config"This is the contents of the published config file:
return [
/*
|--------------------------------------------------------------------------
| Model Configuration
|--------------------------------------------------------------------------
*/
'user_model' => env('WEBHOOKS_USER_MODEL', 'App\\Models\\User'),
'workspace_model' => env('WEBHOOKS_WORKSPACE_MODEL', 'App\\Models\\Workspace'),
'project_model' => env('WEBHOOKS_PROJECT_MODEL', 'App\\Models\\Project'),
/*
|--------------------------------------------------------------------------
| Route Configuration
|--------------------------------------------------------------------------
*/
'register_routes' => env('WEBHOOKS_REGISTER_ROUTES', true),
'route_prefix' => env('WEBHOOKS_ROUTE_PREFIX', ''),
'route_middleware' => ['auth:sanctum'],
/*
|--------------------------------------------------------------------------
| Feature Flags
|--------------------------------------------------------------------------
*/
'workspace_scoped' => env('WEBHOOKS_WORKSPACE_SCOPED', true),
'project_scoped' => env('WEBHOOKS_PROJECT_SCOPED', true),
'track_events' => env('WEBHOOKS_TRACK_EVENTS', true),
];The package provides a Webhook model that you can use to manage your webhooks.
use Whilesmart\Webhooks\Models\Webhook;
$webhook = Webhook::create([
'name' => 'My Webhook',
'user_id' => $user->id,
'project_id' => $project->id,
'workspace_id' => $workspace->id,
'is_active' => true,
]);
// Get the unique ingress URL
echo $webhook->url; // https://your-app.com/webhooks/ingress/{token}Incoming webhooks are sent to a unique URL containing a secure token. When a webhook is triggered:
- The token is validated.
- The
trigger_countandlast_triggered_atfields are updated. - A
WebhookEventis recorded containing the payload and headers. - If
whilesmart/activitiesis installed, an activity log is automatically created.
By default, the package registers the following routes (protected by auth:sanctum):
GET /webhooks: List all webhooks for the authenticated user.POST /webhooks: Create a new webhook.GET /webhooks/{id}: Get webhook details.PATCH /webhooks/{id}: Update a webhook (or regenerate its token).DELETE /webhooks/{id}: Soft delete a webhook.GET /webhooks/{id}/events: List event history for a webhook.
GET /workspaces/{workspaceId}/webhooksPOST /workspaces/{workspaceId}/webhooks- ... (and other CRUD operations prefixed with workspace)
composer testPlease see CHANGELOG for more information on what has changed recently.
The MIT License (MIT). Please see License File for more information.