scolib / laravel-action-log
A laravel package for logging user actions into the database
Requires
- php: >=7.0.0
- scolib/attributes: ~1.0
Requires (Dev)
- laravel/framework: 5.5.*
- mockery/mockery: ^0.9.9
- orchestra/database: ^3.4
- orchestra/testbench: ~3.4
- phpunit/phpunit: ~6.0
- squizlabs/php_codesniffer: ^3.0
Suggests
- jenssegers/agent: Required to use logging client info (~2.5).
README
Install
Laravel 5.5.*
$ composer require scolib/laravel-action-log:1.3.*
Laravel 5.5 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.
Laravel 5.4.*
$ composer require scolib/laravel-action-log:1.2.*
Add the ServiceProvider to the providers
array in config/app.php
\Sco\ActionLog\LaravelServiceProvider::class,
If you want to use the facade to logging actions, add this to the aliases
array in config/app.php
'ActionLog' => Sco\ActionLog\Facade::class,
Publish config file
Copy the package config to your local config with the publish command:
php artisan vendor:publish --provider="Sco\ActionLog\LaravelServiceProvider"
Default action log table name is action_logs
, If you want to customize it, edit the config/actionlog.php
Now run the artisan migrate command:
php artisan migrate
Usage
Method 1
Override the property $events
in your Model
protected $events = [ 'created' => \Sco\ActionLog\Events\ModelWasCreated::class, ];
⚠ Note: Laravel 5.5
Renamed$events
to$dispatchesEvents
(#17961, b6472bf, 3dbe12f)
All available event
[ 'created' => \Sco\ActionLog\Events\ModelWasCreated::class, 'deleted' => \Sco\ActionLog\Events\ModelWasDeleted::class, 'restored' => \Sco\ActionLog\Events\ModelWasRestored::class, 'saved' => \Sco\ActionLog\Events\ModelWasSaved::class, 'updated' => \Sco\ActionLog\Events\ModelWasUpdated::class, 'creating' => \Sco\ActionLog\Events\ModelWillCreating::class, 'deleting' => \Sco\ActionLog\Events\ModelWillDeleting::class, 'restoring' => \Sco\ActionLog\Events\ModelWillRestoring::class, 'saving' => \Sco\ActionLog\Events\ModelWillSaving::class, 'updating' => \Sco\ActionLog\Events\ModelWillUpdating::class, ]
Method 2
Manual logging actions
// use event event(new \Sco\ActionLog\Events\ManualEvent($type, $content)); // use factory \Sco\ActionLog\Factory::info(LogInfo $info);
Change log
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING and CONDUCT for details.
Security
If you discover any security related issues, please email slice1213@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.