Download the PHP package jvizcaya/loggable without Composer
On this page you can find all versions of the php package jvizcaya/loggable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package loggable
Loggable (Provides functions to record user activities in the application models.)
Loggable is a package for Laravel 5.7+ that adds functionalities to record user activities on the tables in the application database, inspired by the haruncpi/laravel-user-activity package.
Loggable saves a record in the logs table each time a user performs an operation on each model that uses the Trait on the created, updated and deleted events.
Installation
We publish the config file if we want to change the table name in the database used by this package, as well as other options.
Run the migration to export the logs table in the database.
Use mode
Add the trait Jvizcaya\Loggable\Loggable
to the model of the table we want the user activity logs to be saved.
That's all, in the previous example a record will be made in the logs table every time a user saves, updates or deletes in the Post model table.
Retrieve models logs
This package was built in using the Laravel one-to-many polymorphic relationship convention and the trait Jvizcaya\Loggable\Loggable
has the model relationship definition.
Load post logs
Lazy Eager Loading
Scope lastLogs($limit = 10, $loadUser = true, $userColumns = 'id,name')
Optionally we can use the scope lastLogs to load the model last logs. This function accepts as the first parameter the maximum number of results.
By default this function loads the user data associated with each log. If we want to select the columns of the user table, we can pass a string with the names of the columns separated by a comma(,) as the third parameter.
To disable the loading of user data, pass a boolean false as the second parameter.
Log model data
By default, model data will be saved to the payload object's data attribute on delete operations. You can disable this functionality by setting the log_data variable in the configuration file to false.
Logs delete (console command)
To delete the activity log data, we can use the available console command loggable:delete, this command will delete the logs that are older than the days defined in the loggable.php configuration file (30 days by default).
Optionally, we can pass the value of the days as the command argument.
Add the console command loggable:delete to Task scheduling for run the command automatically.
Note
This package use the model file Jvizcaya\Loggable\Models\Log
.
License
MIT © Jorge Vizcaya | [email protected]