drewlabs / changelog-eloquent
drewlabs/changelog 库的 Eloquent 驱动器
v0.1.2
2024-03-01 20:21 UTC
Requires
- drewlabs/changelog: ^0.1.0
- illuminate/console: ^9.0|^10.0
- illuminate/database: ^9.0|^10.0
Requires (Dev)
- phpunit/phpunit: ^10.0|^11.0
This package is auto-updated.
Last update: 2024-09-30 21:55:08 UTC
README
提供 Laravel Eloquent 兼容的表变更日志记录器。有关变更日志实现的更多信息,请访问 [https://packagist.org.cn/packages/drewlabs/changelog].
用法
要注册 Eloquent 变更日志驱动程序,只需在 Laravel 应用程序配置中添加提供的服务提供者
// config/app.php return [ // ... 'providers' => [ // ... \Drewlabs\Changelog\Eloquent\ServiceProvider::class, // ... ] ]; ``` The library comes with a command for creating logs table in your application database. In order to run the migration: > php artisan changelog:migrate --refresh --connection=<DATABASE_CONNECTION_NAME> **Note** By default, the command use `mysql` connection if no connection option is passed. **Note** The above configuration allows you to easily log table changes in your application. - Loggable trait The library also comes with a handy trait that can be added to your eloquent model that allows them to log their changes using configured drivers. To provide a model with the logging abilities on changes: ```php <?php // ... use Drewlabs\Changelog\Eloquent\Loggable; use Drewlabs\Changelog\Loggable as AbstractLoggable; class MyModel implements AbstractLoggable { use Loggable; // This method is required by the model and should return the table name used when // logging the model changes into storage public function getLogTableName(): string { return sprintf("locations.%s", $this->getTable()); } } ```