lase-peco/records

1.0 2021-12-21 14:21 UTC

This package is auto-updated.

Last update: 2024-10-22 17:02:38 UTC


README

Latest Version on Packagist Total Downloads

The lase-peco/records is a simple library to record all kind of activities inside your Laravel project. It has practical functions to record the activities in your project. the records will be stored in the records table.

Installation

You can install the package via composer:

composer require lase-peco/records

After installing the package you can create the records table by running the migrations:

php artisan migrate

Usage

The simplest way to use the package is to use the included helper function record():

record('Oh, Something happened here!') // yes, it is that simple!

You can fetch all the records using the Model LasePeCo\Records\Models\Record

use LasePeCo\Records\Models\Record;

Record::all();

Now an advanced example:

record()
    ->by($anElequentModel)
    ->onSubject($anElequentModel)
    ->properties(['someProperty' => 'someValue'])
    ->message('Oh, Something happened here!');

You can retrieve the data from the record as following:

use LasePeCo\Records\Models\Record;

$record = Record::all()->last();

$record->subject; //returns an instance of an eloquent model
$record->causer; //returns an instance of an eloquent model
$record->properties; //returns an array ['someProperty' => 'someValue']
$record->message; //returns 'Oh, Something happened here!'

If you don't provide the causer, when creating the record, then by default the authenticated user will be added as a causer for the record. If there is no authenticated user, then the causer will be null.

Options

Optionally you can save the IP of the request in your record by chaining the withIp() method on the helper function record(). The IP will be anonymized and saved in the record.

record('Oh, Something happened here!')->withIp();

use LasePeCo\Records\Models\Record;

$record = Record::all()->last();

$record->ip // return 12.214.31.***

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email a.dabak@lase-peco.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.