Download the PHP package igaster/laravel-model-events without Composer
On this page you can find all versions of the php package igaster/laravel-model-events. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download igaster/laravel-model-events
More information about igaster/laravel-model-events
Files in igaster/laravel-model-events
Package laravel-model-events
Short Description Laravel Custom Model Events
License MIT
Homepage https://github.com/igaster/laravel-model-events.git
Informations about the package laravel-model-events
Description
This is as simple as keeping a diary for your models!
You can record a short message for any model with current timestamp and authenticated user.
Installation:
A) Execute composer require igaster/laravel-model-events
This package includes a Service Provider that will be automatically discovered by Laravel.
B) Run migrations.
This will create a table log_model_events
that will be used to store events.
Usage:
Step 1: Add a Trait to your model:
Step 2: Log yout events:
a) Manually
Use the logModelEvent("Description")
method to log any event
- The
logModelEvent()
method will also log a) the current authenticated user and b) the related model instance c) current timestamp - This is a public method. You may also call it from your
$model
instance from anywhere
b) Automatically capture laravel model events:
Eloquent models fire several events during updating, creating etc. These events can be automatically logged. Just define these events inside the $logModelEvents
static array in your model:
- Now every time this model instance is changed, the event will be logged and attributed to the authenticated user.
- As a bonus a report of all the updated attributes will be added in the description!
Step 3: Fetch a list of events:
a) From a $model
instance:
b) From a $user
instance:
In order to query events from a $user model you must first include this trait with the User class: Note: This trait is optional for the rest functions of this package!
c) Build your own queries:
All relationships with the LogModelEvent
model have been implemented. These are some valid queries:
Step 4: Display Events:
a) Manually
Through a LogModelEvents
model you can retrieve the $user
and the $model
instances:
Note the the $modelEvent->model
is a polymorphic relationship and it will retrieve a $model
instance on its respective class.
b) Use package sample view:
You may include the model-events::modelEvents
partial in your views to render a list of events:
Available parameters are: model
, user
, count_events
. All are optional