Download the PHP package protechstudio/oplogger without Composer
On this page you can find all versions of the php package protechstudio/oplogger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download protechstudio/oplogger
More information about protechstudio/oplogger
Files in protechstudio/oplogger
Package oplogger
Short Description It offers a convenient way to create a user operation log for any Laravel 5 application. Supports parameters and writes log to database by default but can also be linked to different repositories.
License MIT
Informations about the package oplogger
Oplogger
It offers a convenient and fast way to create a user operation log for any Laravel 5 application. It supports parameters and writes log to database by default but can also be used with a custom repository.
Installation
Require this package with composer using the following command:
After updating composer, add the service provider to the providers
array in config/app.php
You may also add the Facade in the aliases
array in config/app.php
Finally publish the configuration and migration files using the artisan command
You may also publish only the configuration file or the migration using the associated config
and migrations
tags
Run the migration ( only needed if you intend to use the internal repository )
Configuration
Open the published configuration file at config/oplogger.php
:
Then populate the types
array with all operation types with their specific message.
If you intend to use a custom repository you must edit the repository
element.
Using a custom repository
The custom repository must implement the LogRepositoryContract
as in the example below:
Usage
You may use the Oplogger service in two ways:
Using the dependency or method injection
Using the Facade
Adding parameters to the operation string
The write
method uses the vsprintf
function internally so you may easily add any parameter you need to the type operation string in the config/oplogger.php
Then you can pass an array of parameters as the second argument of the write
method
For advance use of parameters please check the vsprintf documentation.
Operation associated user
Oplogger
automatically retrieves the logged in user using the Laravel Auth
system. If you prefer you may also force to log the operation with a specific user passing the user id as the third argument
The internal repository
If you are using the internal repository, running the published migration will create a logs
table with user_id
, operation
and laravel timestamp fields.
Please note that if you are not using the laravel default users table for users you should edit the migration accordingly or an exception will be thrown due to the user_id foreign key constraint.
You may access the underlying Log
model adding use Protechstudio\Oplogger\Models\Log;
to the use statements.
Exceptions
Typing a wrong operation type key
If the operation key you type in the write
method is not present in your configuration types
array an OploggerKeyNotFoundException
exception will be thrown.
Not providing a user for the operation
If you don't provide a specific user for the operation and the user is not logged in an OploggerUserNotLoggedException
exception will be thrown.