Download the PHP package denismitr/laravel-event-recorder without Composer

On this page you can find all versions of the php package denismitr/laravel-event-recorder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-event-recorder

Laravel Event Recorder

Build Status

Author

Denis Mitrofanov

Requirements

PHP 7.0 or higher MYSQL 5.7 or higher or POSTGRES probably any 9.* version or higher will do Laravel >=5.5

Version 2.x

Overview

Any class that should be recorded to DB must implement the Denismitr\EventRecorder\Contracts\ShouldBeRecorded interface or extend Denismitr\EventRecorder\ConditionallyRecordable abstract class that gives ability to record events only under certain conditions. Both ways enforce the concrete implementation of two methods getProperties(): array and getDescription(): string methods, plus a method public function shouldBeSkipped(): bool, in case of extending the abstract class, can be overridden when you wish to skip the recording of event under certain conditions. Properties returned by the getProperties() are an arbitrary array of important key-value pairs for the given event that you wish to log/persist. (see example below). getDescription(): string is just a human readable form of the event that occurred. The properties are stored in json format and description is a VARCHAR 512 (configurable) string field.

Installation

Via composer composer require denismitr/laravel-event-recorder

In Laravel 5.5 the service provider will automatically get registered. But you can register it manually too in the config/app.php file:

You can publish the migration with:

You can publish the config file with:

After the migration has been published and you are happy with configuration, run the mirations: php artisan migrate

Usage

Let's imagine we have a MoneyAddedToWallet event:

Or another option with inheritance:

After it is fired. A record in the recorded_events table will be created. The following extract from test file hopefully explains what is going on.

Two important things to notice:

Triggered By

As of version 1.0 package supports recording an ID of a user who triggered an event and as of version 2.0 also you can store arbitrary attributes of the user. If you use a trait Denismitr\EventRecorder\TriggeredByUser in the event class you wish to record, when event occurs the user who is currently logged in ID will be saved along with other data for this event. The DB column in recorded_events used for this is called triggered_by_id. There is a Laravel belongsTo relationship defined in RecordedEvents model. This way you can retrieve an instance of a user whose actions have triggered the event.

As of version 2.0 there is a nullable triggered_by_properties column added to the schema. And a new trait Denismitr\EventRecorder\Traits\CanTriggerEvents that is responsible for picking, filtering the user data for stroing into that column. Use of this trait is optional. By default it will persist all attributes that the given User model has, except for those included in the standard Laravel User model $hidden array. You can further control what attributes should not be persisted by adding public $eventAttributeBlacklist = []; to your User model and filling it with attributes you wish to exclude.

Since this trait is responsible only for storing user data as json, not using it will not prevent the storing of user id as triggered_by_id that is fully the responsibility of the Denismitr\EventRecorder\TriggeredByUser and the event class where it is being used.

Configuration

The contents of configuration file is as follows:

If you need to change some of these properties, be sure to do that before you actually run the php artisan migrate, otherwise you will have to do either php artisan migrate:fresh or if it is already impossible, you would have to manually create the logic for changing your DB schema.


All versions of laravel-event-recorder with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0
denismitr/laravel-json-attributes Version ^1.0
illuminate/console Version ~5.5.0|~5.6.0
illuminate/database Version ~5.5.0|~5.6.0
illuminate/events Version ~5.5.0|~5.6.0
illuminate/support Version ~5.5.0|~5.6.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package denismitr/laravel-event-recorder contains the following files

Loading the files please wait ....