Skip to content

Commit e27ee71

Browse files
Added action logging documentation
1 parent 8450dc7 commit e27ee71

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

docs/usage.md

+30
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ You can use any existing eloquent model with this package without any modificati
44

55
## Record Events
66

7+
### Model Creation
8+
79
To record the created event use the `History::begin()` method:
810

911
```php
@@ -14,6 +16,8 @@ $project = Project::create(['name' => 'Giga Project', 'category' => 'Constructio
1416
History::begin($project);
1517
```
1618

19+
### Model Updates
20+
1721
Record updates can be stored as well:
1822

1923
```php
@@ -46,19 +50,45 @@ $project->update(['category' => 'Investment']);
4650
History::logRecentUpdate($project, "Reclassified as per the CEO's request");
4751
```
4852

53+
### Comments Without Field Changes
54+
4955
Comment only entries can be added:
5056

5157
```php
5258
History::addComment($project, 'Expiry in 10 days');
5359
```
5460

61+
### Deletion Events
62+
5563
Model deletion can be logged as well:
5664

5765
```php
5866
$project->delete();
5967
History::logDeletion($project);
6068
```
6169

70+
### Record Action Execution
71+
72+
It can happen that your model is doing "actions", like a report being executed,
73+
or a notification being triggered, and you want to add this event to the history.
74+
75+
In such cases there are no field changes, and you just report the fact whether
76+
the action has succeeded or failed:
77+
78+
```php
79+
try {
80+
$report->execute();
81+
History::logActionSuccess($report);
82+
} catch (\Throwable $e) {
83+
History::logActionFailure($report, $e->getMessage());
84+
}
85+
```
86+
87+
The generated action events have a `was_successful` boolean property which indicates whether the action ran
88+
successfully or failed.
89+
90+
> For non-action events, the `was_successful` field is `null` indicating that there's no "success" information available
91+
6292
## Retrieve History Events
6393

6494
To get the list of event of a model use the following code:

0 commit comments

Comments
 (0)