Download the PHP package codemyviews/activitylog without Composer
On this page you can find all versions of the php package codemyviews/activitylog. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codemyviews/activitylog
More information about codemyviews/activitylog
Files in codemyviews/activitylog
Package activitylog
Short Description A very simple activity logger to monitor the users of your website or application
License MIT
Homepage https://github.com/codemyviews/activitylog
Informations about the package activitylog
Log the activity of your users
This Laravel 5 package provides a very easy to use solution to log the activities of the users of your Laravel 5 app. All the activities will be logged in a db-table. Optionally the activities can also be logged against the default Laravel Log Handler.
This package was originally created by Spatie. Spatie is a web design agency in Antwerp, Belgium. You'll find an overview of all their open source projects on their website.
Later we in CodeMyViews decided to modify Spatie version to better fit our needs. You can read about us on our site.
Installation
This package can be installed through Composer.
This service provider must be registered.
You'll also need to publish and run the migration in order to create the db-table.
Activitylog also comes with a facade, which provides an easy way to call it.
Optionally you can publish the config file of this package.
The configuration will be written to . The options provided are self explanatory.
Usage
Manual logging
Logging some activity is very simple.
The string you pass to function gets written in a db-table together with a timestamp, the IP address, the user agent of the user, and reference to the model.
Log model events
This package can log the events from your models. To do so, your model must use the LogsActivity
-trait and implement LogsActivityInterface
.
The interface expects you to implement the getActivityDescriptionForEvent
-function.
Here's an example of a possible implementation.
The result of this function will be logged unless the result is an empty string. Logged activities will be referencing the model, which has created them.
Using a before handler.
If you want to disable logging under certain conditions,
such as for a particular user, create a class in your application
namespace that implements the CodeMyViews\Activitylog\Handlers\BeforeHandlerInterface
.
This interface defines a shouldLog()
method in which you can code any custom logic to determine
whether logging should be ignored or not. You must return true
the call should be logged.
To en the namespaced class name to the beforeHandler
field in the configuration file:
For example, this callback class could look like this to disable logging a user with the id of 1:
Retrieving logged entries
All events will be logged in the activity_log
-table. This package provides an Eloquent model to work with the table. You can use all the normal Eloquent methods that you know and love. Here's how you can get the last 100 activities together with the associated users.
Cleaning up the log
Over time, your log will grow. To clean up the database table you can run this command:
By default records, older than 2 months will be deleted. The number of months can be modified in the configuration file of the package.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Freek Van der Herten
- Ivan Kulikov
- All Contributors
License
The MIT License (MIT). Please see License File for more information.