https://github.com/efureev/laravel-action-events
Allows you to store various event actions: model changes, events, just strings
https://github.com/efureev/laravel-action-events
Last synced: about 2 months ago
JSON representation
Allows you to store various event actions: model changes, events, just strings
- Host: GitHub
- URL: https://github.com/efureev/laravel-action-events
- Owner: efureev
- License: other
- Created: 2021-07-30T18:34:18.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-08-02T10:22:50.000Z (over 3 years ago)
- Last Synced: 2025-01-15T09:03:03.287Z (3 months ago)
- Language: PHP
- Size: 40 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Event log system
## Information
This package allows you to store various event actions: model changes, events, just strings
### Features
- Keep `original` & `change` data
- Keep `Extra` data
- Store various value types: `String`, `Event`, `Model`
- Has various event types:
- `Change` For change data Actions (Models: create/update/delete)
- `Event` For any Events in system (Login success/failed)
- `Read` For read data (Export data, etc)
- Store an event with a model in one transaction
- Has relations (through trait: `HasActions`) to the Eloquent Models: `$model->actions`
- Has relation (through trait: `MadeActions`) to author user: `$user->madeActions`
- Has statuses: `Done`, `Running`, `Failed`## Examples
Log event from `String`
```php
app('actionEvents')->push('custom event');
```Log event from Laravel `Event` with interface `Actionable`
```php
class Login implements Actionable
{
public function getName(): string
{
return 'login';
}
}// ...
app('actionEvents')->push(new Login());
```Log event from Laravel `Event` wo interface `Actionable`
```php
class CustomEvent
{
}// ...
app('actionEvents')->push(new CustomEvent());
```Log event from special class `ActionEvent` or other which implementing interface `ActionEventable`
```php
app('actionEvents')->push(new ActionEvent('event'));
app('actionEvents')->push(ActionEvent::make('event')->typeRead());
app('actionEvents')->push(new ActionEvent('event', ActionEventType::READ));
```Log data change from Laravel Model: create
```php
$attributes = [
// ...
];
$dataModel = User::create($attributes);
$modelEvent = app('actionEvents')->pushByModelCreate($dataModel);
```Log data change from Laravel Model: update
```php
$attributes1 = [
// ...
];
$dataModel = User::create([]);
$dataModel->fill(['name'=>'test']);$modelEvent = app('actionEvents')->pushByModelUpdate($dataModel);
$dataModel->save();
```or
```php
$attributes1 = [
// ...
];
$dataModel = User::create([]);
$dataModel->fill(['name'=>'test']);
$changes = $dataModel->getDirty();
$dataModel->save();$modelEvent = app('actionEvents')->pushByModelUpdate($dataModel, $changes);
```Log data change from Laravel Model with transaction: create
```php
$attributes1 = [
// ...
];
$dataModel = User::create([]);
$modelEvent = app('actionEvents')->pushAndSaveByModelCreate($dataModel);
```Log data change from Laravel Model with transaction: update
```php
$attributes1 = [
// ...
];
$dataModel = User::create([]);
$dataModel->fill(['name'=>'test']);
$modelEvent = app('actionEvents')->pushAndSaveByModelUpdate($dataModel);
```### Work with collections
Target-models & ActionEvent-models store in `pushCollectionCreate` or `pushCollectionUpdate` through transactions.
Log collections: create
```php
$staffModels = new Collection([Model::create(), Model::make(),'test', new Login(),Model::create()]);
$models = app('actionEvents')->pushCollectionCreate($staffModels);
```If target-model have not created, it will be store before its logging to actionEvent store to define its ID.
Log collections: update
```php
$models = StuffFactory::times(10)->create();
$models->each(fn(Stuff $model) => $model->setAttribute('name', $model->name . ' (updated)'));// add other item types to store
$models->add('time');
$models->add(new Login());$eventModels = app('actionEvents')->pushCollectionUpdate($models);
```Log collections: delete
```php
$models = StuffFactory::times(10)->create();
$models->delete();
$eventModels = app('actionEvents')->pushCollectionDelete($models);
```