weblabnl / laravel-webhook-call
:package_description
Requires
- php: ^8.0
- illuminate/contracts: ^9.0|^10.0
- spatie/laravel-package-tools: ^1.13.0
- spatie/laravel-webhook-server: ^3.4
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
This package is not auto-updated.
Last update: 2024-09-20 20:31:31 UTC
README
Webhook 是一种应用程序向其他应用程序提供实时信息的方式。当应用程序中发生事件时,会以 HTTP 请求的形式向已注册的 webhook 发送通知。
此包允许您轻松地将 webhook 端点和事件存储在数据库中,同时 webhook 调用的结果将记录在数据库中。它基于优秀的 spatie/laravel-webhook-server 包构建,该包提供了诸如签名调用和重试失败调用等功能。此包使管理跟踪 webhook 及其相关数据变得更加容易并添加了更多功能。
使用此包,您可以轻松地管理和跟踪您的 webhook,从而在之上构建管理 webhook 的接口。
安装
您可以通过 composer 安装此包
composer require weblabnl/laravel-webhook-call
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="Weblab\WebhookCall\WebhookCallServiceProvider"
以下是要在 config/webhook-call.php
中发布的文件内容。您可以根据需要更改默认值,并引入自己的顶级模型对象。
return [ // the model to use for the webhook calls 'models' => [ // The model that should be used to store the webhook endpoint data. 'webhook' => \Weblab\WebhookCall\Models\Webhook::class, // The model that should be used to store the webhook event data. 'webhook_event' => \Weblab\WebhookCall\Models\WebhookEvent::class, // The model that should be used to store the webhook log data. 'webhook_log' => \Weblab\WebhookCall\Models\WebhookLog::class, ], ];
安装包后,您可以使用以下命令运行迁移
php artisan migrate
用法
调用 webhook 简单如
// fetch a webhook from the database $webhook = Webhook::find(1); // call the webhook WebhookCall::create() ->wehbook($webhook) ->dispatch();
Webhook 日志记录
除了在数据库中存储 webhook 端点和事件外,此包还提供了 webhook 调用结果的详细日志。成功和失败的结果都存储在数据库中,并包括端点响应代码、响应和原始有效负载等信息。这使得跟踪和解决 webhook 中的任何问题变得容易。
为日志提供 webhook 事件
在调用 webhook 时,您可以为日志提供一个事件。
// fetch a webhook from the database $webhook = Webhook::find(1); $webhookEvent = $webhook->webhookEvents() ->where('name', 'order.created') ->first(); // call the webhook WebhookCall::create() ->wehbook($webhook) ->webhookEvent($webhookEvent) ->dispatch();
之后,webhook 事件将在与该 webhook 调用相关的任何日志条目中可用
与 webhook 数据相关的实体
在调用 webhook 时,您可以为日志提供一个实体。
// fetch a webhook from the database $webhook = Webhook::find(1); // fetch an entity from the database $entity = Order::find(1); // call the webhook WebhookCall::create() ->wehbook($webhook) ->entity($entity) ->dispatch();
之后,该实体将在与该 webhook 调用相关的任何日志条目中可用
更多选项
更多测试选项和 WebhookCall 类的选项可以在 spatie/laravel-webhook-server github 页面上找到
测试
composer test
更新日志
请参阅 CHANGELOG 了解最近更改的信息。
安全
如果您发现任何与安全相关的问题,请通过电子邮件 development@weblab.nl 而不是使用问题跟踪器。
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。