### Install and configure laravel-webhooks Source: https://github.com/jeffersongoncalves/laravel-webhooks/blob/main/resources/boost/skills/webhooks-development/SKILL.md Install the package and publish its configuration and migration files, then run migrations to set up the database tables. ```bash composer require jeffersongoncalves/laravel-webhooks php artisan vendor:publish --tag=laravel-webhooks-config php artisan vendor:publish --tag=laravel-webhooks-migrations php artisan migrate ``` -------------------------------- ### Install laravel-webhooks with Composer Source: https://github.com/jeffersongoncalves/laravel-webhooks/blob/main/README.md Installs the package via Composer. Laravel's auto-discovery registers the service provider and the Webhooks facade automatically. ```bash composer require jeffersongoncalves/laravel-webhooks ``` -------------------------------- ### Run tests with composer test Source: https://github.com/jeffersongoncalves/laravel-webhooks/blob/main/README.md Runs the test suite for the package. Requires Composer to be installed. ```bash composer test ``` -------------------------------- ### Send a test webhook with Webhooks::test Source: https://github.com/jeffersongoncalves/laravel-webhooks/blob/main/README.md Dispatch a sample payload synchronously using the Webhooks facade and get back the resulting log entry. Useful for 'Send test' buttons. ```php use JeffersonGoncalves\Webhooks\Facades\Webhooks; use JeffersonGoncalves\Webhooks\Models\Webhook; $log = Webhooks::test(Webhook::find(1)); ``` -------------------------------- ### Publish and run laravel-webhooks migrations Source: https://github.com/jeffersongoncalves/laravel-webhooks/blob/main/README.md Publishes and runs the migrations. Creates the webhooks and webhook_logs tables. ```bash php artisan vendor:publish --tag=laravel-webhooks-migrations php artisan migrate ``` -------------------------------- ### Publish laravel-webhooks configuration Source: https://github.com/jeffersongoncalves/laravel-webhooks/blob/main/README.md Publishes the package configuration file. ```bash php artisan vendor:publish --tag=laravel-webhooks-config ``` -------------------------------- ### Register a webhook endpoint with Webhook::create Source: https://github.com/jeffersongoncalves/laravel-webhooks/blob/main/README.md Create a webhook endpoint record in the database. The 'secret' is optional and enables signing; 'model' can be null to listen to every model. After registration, creating or updating an Order automatically delivers an HTTP POST to the URL. ```php use JeffersonGoncalves\Webhooks\Enums\WebhookEvent; use JeffersonGoncalves\Webhooks\Models\Webhook; Webhook::create([ 'name' => 'Order notifications', 'url' => 'https://example.com/webhooks/orders', 'secret' => 'a-shared-secret', // optional, enables signing 'events' => [WebhookEvent::Created->value, WebhookEvent::Updated->value], 'model' => Order::class, // null = listen to every model 'is_active' => true, ]); ``` -------------------------------- ### Publish laravel-webhooks translations Source: https://github.com/jeffersongoncalves/laravel-webhooks/blob/main/README.md Publishes the translation files (optional). ```bash php artisan vendor:publish --tag=laravel-webhooks-translations ``` -------------------------------- ### Force queueing with ShouldQueueWebhook trait Source: https://github.com/jeffersongoncalves/laravel-webhooks/blob/main/README.md Force a specific model to always queue webhook requests regardless of the global 'webhooks.queue' setting. By default requests are queued; set 'webhooks.queue' to false to send synchronously. ```php use JeffersonGoncalves\Webhooks\Concerns\AllWebhooks; use JeffersonGoncalves\Webhooks\Concerns\ShouldQueueWebhook; class Order extends Model { use AllWebhooks; use ShouldQueueWebhook; } ``` -------------------------------- ### Broadcast model events with AllWebhooks trait Source: https://github.com/jeffersongoncalves/laravel-webhooks/blob/main/resources/boost/skills/webhooks-development/SKILL.md Add the AllWebhooks trait to a model to broadcast created, updated, and deleted events to registered webhooks. ```php use JeffersonGoncalves\Webhooks\Concerns\AllWebhooks; class Order extends Model { use AllWebhooks; } ``` -------------------------------- ### Fetch webhook delivery logs Source: https://github.com/jeffersongoncalves/laravel-webhooks/blob/main/README.md Retrieve the most recent delivery logs for a webhook. Every delivery (success or failure) is recorded in the webhook_logs table when logging is enabled, capturing URL, payload, response status, response body, attempt number, and error message. ```php use JeffersonGoncalves\Webhooks\Models\Webhook; $webhook = Webhook::find(1); $webhook->logs()->latest()->get(); ``` -------------------------------- ### Disable logging in config Source: https://github.com/jeffersongoncalves/laravel-webhooks/blob/main/README.md Disable logging globally by setting the 'logging.enabled' config value to false. ```php 'logging' => [ 'enabled' => false, ], ``` -------------------------------- ### Customize webhook payload with webhookCreatedPayload or webhookPayload Source: https://github.com/jeffersongoncalves/laravel-webhooks/blob/main/resources/boost/skills/webhooks-development/SKILL.md Override webhookCreatedPayload for a single event or webhookPayload for all events to customize the data sent in the webhook body. The final body is always ['event' => ..., 'model' => FQCN, 'data' => ]. ```php public function webhookCreatedPayload(): array { return ['id' => $this->id, 'total' => $this->total]; } // or, for every event: public function webhookPayload(\JeffersonGoncalves\Webhooks\Enums\WebhookEvent $event): array { return $this->only(['id', 'status']); } ``` -------------------------------- ### Customize payload for a specific event Source: https://github.com/jeffersongoncalves/laravel-webhooks/blob/main/README.md Override the payload for a specific event by implementing the matching method on the model. Available overrides are webhookCreatedPayload(), webhookUpdatedPayload(), and webhookDeletedPayload(). ```php use JeffersonGoncalves\Webhooks\Concerns\CreatedWebhook; class Order extends Model { use CreatedWebhook; public function webhookCreatedPayload(): array { return [ 'id' => $this->id, 'total' => $this->total, 'status' => $this->status, ]; } } ``` -------------------------------- ### Override webhookPayload for all events Source: https://github.com/jeffersongoncalves/laravel-webhooks/blob/main/README.md Override webhookPayload() to change the payload for every event at once. The method receives the WebhookEvent enum instance. ```php use JeffersonGoncalves\Webhooks\Enums\WebhookEvent; public function webhookPayload(WebhookEvent $event): array { return [ 'id' => $this->id, 'event' => $event->value, ]; } ``` -------------------------------- ### Webhook payload envelope Source: https://github.com/jeffersongoncalves/laravel-webhooks/blob/main/README.md The JSON envelope sent to the webhook endpoint. It always contains 'event', 'model', and 'data' keys; 'data' defaults to $model->toArray(). ```json { "event": "created", "model": "App\\Models\\Order", "data": { "id": 1, "total": 9990 } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.