inmanturbo/modelware

laravel 的 Eloquent Modelware

v1.0.3 2024-08-10 20:52 UTC

This package is auto-updated.

Last update: 2024-09-10 20:58:35 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

安装

您可以通过 composer 安装此包

composer require inmanturbo/modelware

用法

在服务提供者的 boot 方法中添加 modelware

use Inmanturbo\Modelware\Facades\Modelware;

Modelware::add('eloquent.updating*', [
    EnsureModelShouldBeSaved::class,
    ValidateAttributes::class,
    FillModel::class,
], prefix: 'modelware'); // modelware is the default

此包通过 pipelines(类似于中间件)发送事件数据,这些 pipelines 通过以下语法将可调用的类集合绑定到并从服务容器中解析出来:

    app()->bind("{$prefix}.{$event}", function () use ($pipes) {
        return collect($pipes)->map(fn ($pipe) => app($pipe));
    });

其中 {$event} 是 eloquent 的 通配事件

  • modelware.eloquent.creating* => eloquent.creating*
  • modelware.eloquent.updating* => eloquent.updating*
  • modelware.eloquent.deleting* => eloquent.deleting*

此包将通过您的自定义 pipeline 发送以下数据对象

$data = app(Data::class, [
    'event' => $events,
    'model' => $payload[0],
    'payload' => $payload,
]);

测试

composer test

更新日志

有关最近更改的更多信息,请参阅更新日志

贡献

有关详细信息,请参阅贡献指南

安全漏洞

请查阅我们的安全策略了解如何报告安全漏洞

致谢

许可证

MIT 许可证(MIT)。有关更多信息,请参阅许可证文件