定制 scito/eloquent-webhooks 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

scito/eloquent-webhooks

最新稳定版本:1.01

Composer 安装命令:

composer require scito/eloquent-webhooks

包简介

Fire webhooks based on eloquent events

README 文档

README

Dispatch http requests on model events with zero configuration.

Installation

Install the package.

composer require scito/eloquent-webhooks

Run the migration to create eloquent_webhooks table.

php artisan migrate

If you don't have auto discovery add the service provider in config/app.php.

'providers' = [
    Scito\EloquentWebhooks\Providers\WebhookServiceProvider::class,

    // ...
];

Configuration

Add the Webhooks trait in your model. Out of the box all published properties of your model will be available during the evaluation of the shortcodes in your webhook url.

use Illuminate\Database\Eloquent\Model;
use Scito\EloquentWebhooks\Traits\Webhooks;

class Post extends Model
{
    use Webhooks;

    // ...
}

The shotcodes in a webhook will be evaluated against $model->toArray().

You can customize the data to evaluate by adding webhookData() in your model.

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Scito\EloquentWebhooks\Models\EloquentWebhook;
use Scito\EloquentWebhooks\Traits\Webhooks;

class Post extends Model
{
    use Webhooks;

    public function author(): BelongsTo
    {
        return $this->belongsTo(Author::class);
    }

    public function webhookData(EloquentWebhook $webhook): array
    {
        return [
            'title' => $this->name,
            'author' => $this->author->name,
        ];
    }

    // ...
}

Creating webhooks

use Scito\EloquentWebhooks\Models\EloquentWebhook;

EloquentWebhook::create([
    'model' => Post::class,
    'event' => 'created',
    'status' => 'active',
    'method' => 'get',
    'link' => 'https://example.com?name={title}&author={author}',
]);

You can also dispatch post requests, webhookData() / $model->toArray() will be sent as request payload.

use Scito\EloquentWebhooks\Models\EloquentWebhook;

EloquentWebhook::create([
    'model' => Post::class,
    'event' => 'created',
    'status' => 'active',
    'method' => 'post',
    'link' => 'https://example.com',
]);

统计信息

  • 总下载量: 12.58k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-11-22