@@ -4,6 +4,8 @@ You can use any existing eloquent model with this package without any modificati
4
4
5
5
## Record Events
6
6
7
+ ### Model Creation
8
+
7
9
To record the created event use the ` History::begin() ` method:
8
10
9
11
``` php
@@ -14,6 +16,8 @@ $project = Project::create(['name' => 'Giga Project', 'category' => 'Constructio
14
16
History::begin($project);
15
17
```
16
18
19
+ ### Model Updates
20
+
17
21
Record updates can be stored as well:
18
22
19
23
``` php
@@ -46,19 +50,45 @@ $project->update(['category' => 'Investment']);
46
50
History::logRecentUpdate($project, "Reclassified as per the CEO's request");
47
51
```
48
52
53
+ ### Comments Without Field Changes
54
+
49
55
Comment only entries can be added:
50
56
51
57
``` php
52
58
History::addComment($project, 'Expiry in 10 days');
53
59
```
54
60
61
+ ### Deletion Events
62
+
55
63
Model deletion can be logged as well:
56
64
57
65
``` php
58
66
$project->delete();
59
67
History::logDeletion($project);
60
68
```
61
69
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
+
62
92
## Retrieve History Events
63
93
64
94
To get the list of event of a model use the following code:
0 commit comments