mintbridge / eloquent-auditing
将模型事件记录到数据库的优雅包
v0.0.5
2017-01-15 11:55 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- mockery/mockery: 0.9.*
- phpunit/phpunit: 4.2.*
Suggests
- illuminate/support: Required for Laravel support
This package is not auto-updated.
Last update: 2024-09-14 19:36:34 UTC
README
此 Laravel 5 包允许将模型事件记录到数据库。它提供了一个可以添加到任何 Eloquent 模型中的特质,允许使用多态关系记录所选事件。
安装
此包可以通过 Composer 安装。
composer require mintbridge/eloquent-auditing
安装后,将服务提供者和外观添加到您的应用程序配置中
// config/app.php 'providers' => [ '...', Mintbridge\EloquentAuditing\AuditServiceProvider::class, ]; 'aliases' => [ ... 'Auditor' => Mintbridge\EloquentAuditing\AuditorFacade::class, ];
您还需要发布并运行迁移以创建数据库表。
php artisan vendor:publish --provider="Mintbridge\EloquentAuditing\AuditServiceProvider" --tag="config"
php artisan vendor:publish --provider="Mintbridge\EloquentAuditing\AuditServiceProvider" --tag="migrations"
php artisan migrate
配置将写入 config/auditing.php。选项有合理的默认值,但您应该更改用户以匹配应用程序中使用的用户。
使用
此包将记录您的模型的事件。为此,您的模型必须使用 Auditable 特质并实现 AuditableInterface。
use Mintbridge\EloquentAuditing\Auditable; use Mintbridge\EloquentAuditing\AuditableInterface; class Article extends Eloquent implements AuditableInterface { use Auditable; ...
默认情况下,特质将使用 config/auditing.php 中的事件,但您可以通过将静态 $auditableEvents 数组(包含事件名称)添加到模型中,在特定模型的基础上覆盖此设置。有关可用事件的详细信息,请参阅 https://laravel.net.cn/docs/5.1/eloquent#events。
use Mintbridge\EloquentAuditing\Auditable; use Mintbridge\EloquentAuditing\AuditableInterface; class Article extends Eloquent implements AuditableInterface { use Auditable; public static $auditableEvents = [ 'creating', 'created', 'updating', //... ]; ...
贡献
有关详细信息,请参阅 CONTRIBUTING。
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。