Download the PHP package elaborate-code/laravel-eloquent-logs without Composer
On this page you can find all versions of the php package elaborate-code/laravel-eloquent-logs. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download elaborate-code/laravel-eloquent-logs
More information about elaborate-code/laravel-eloquent-logs
Files in elaborate-code/laravel-eloquent-logs
Package laravel-eloquent-logs
Short Description A simple way to log changes that occur on Eloquent models
License MIT
Homepage https://github.com/elaborate-code/laravel-eloquent-logs
Informations about the package laravel-eloquent-logs
laravel-eloquent-logs
Log what happens to your Eloquent models (created
|updated
|deleted
|soft deleted
|restored
|force deleted
) and keep and eye on who made the change, how and when.
This solution is simple to integrate and introduces minimal changes to your project: 1 migration, 1 model, 1 trait, and 1 facade.
Installation
Install the package via composer:
Publish the migrations:
Run the migrations:
Publishing config file [Optional]
You can publish the config file with:
This is the contents of the published config file:
That allows you to rename the logs_table
before running the migrations.
Usage
Pick an Eloquent model that you want to log the changes that happen to it and add the HasLogs
trait to it.
After adding that trait, every change made to the model will be recorded.
Important warning from Laravel docs
When issuing a mass update or delete query via Eloquent, the
saved
,updated
,deleting
, anddeleted
model events will not be dispatched for the affected models. This is because the models are never actually retrieved when performing mass updates or deletes.
Retrieving logs
You can load a model's logs using the eloquentLogs
relationship:
And you can query logs directly:
Grouping queries
By default each one model event will result in a query to log the action.
You can improve the logging process by using the CacheEloquentLogQueries
facade
The facade includes other methods that you wouldn't necessarily need to use:
Ignoring events
You can specify the events to not log on the model instances by listing the events to ignore on YourModel::$loggableOptions['ignore']
.
Muting Eloquent events [Laravel stuff]
From seeders:
Anywhere from your code:
Explore the Eloquent docs for more options
Alternative
Among the bajillion packages that Spatie has so graciously bestowed upon the community, you'll find the excellent laravel-Alternative package.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- medilies
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-eloquent-logs with dependencies
spatie/laravel-package-tools Version ^1.9.2
illuminate/contracts Version ^9.0