Skip to content

Commit 966ddab

Browse files
committed
Update code samples with changes in version 1.8.0
Describe that from version 1.8.0 onwards `creating`, `created`, `updating`, `updated`, and `saved` event hooks must return the `$model` instance. Add documentation and code sample for `saved` event hook. Remove `return $data` from `deleting` and `deleted` code samples, and instead add comment on what the code may do on each case.
1 parent 6438941 commit 966ddab

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

editor-events.md

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,20 @@ Create action has the following event hooks:
1313
To use the event hook, just add the methods on your editor class.
1414

1515
```php
16-
public function creating(Model $model, array $data) {
17-
return $data;
16+
public function creating(Model $model, array $data)
17+
{
18+
// Prior to version 1.8.0 of Laravel DataTables Editor the hook was not required
19+
// to return the $model.
20+
// In version 1.8.0+ the hook must return the $model instance:
21+
return $model;
1822
}
1923

20-
public function created(Model $model, array $data) {
21-
return $data;
24+
public function created(Model $model, array $data)
25+
{
26+
// Prior to version 1.8.0 of Laravel DataTables Editor the hook was not required
27+
// to return the $model.
28+
// In version 1.8.0+ the hook must return the $model instance:
29+
return $model;
2230
}
2331
```
2432

@@ -34,11 +42,34 @@ To use the event hook, just add the methods on your editor class.
3442

3543
```php
3644
public function updating(Model $model, array $data) {
37-
return $data;
45+
// Prior to version 1.8.0 of Laravel DataTables Editor the hook was not required
46+
// to return the $model.
47+
// In version 1.8.0+ the hook must return the $model:
48+
return $model;
3849
}
3950

4051
public function updated(Model $model, array $data) {
41-
return $data;
52+
// Prior to version 1.8.0 of Laravel DataTables Editor the hook was not required
53+
// to return the $model.
54+
// In version 1.8.0+ the hook must return the $model instance:
55+
return $model;
56+
}
57+
```
58+
59+
<a name="saved-event"></a>
60+
## Saved event
61+
62+
In addition to create and edit events, the `saved` event hook is called after `created` and `saved`.
63+
64+
To use the event hook, just add the method on your editor class:
65+
66+
```php
67+
public function saved(Model $model, array $data)
68+
{
69+
// Prior to version 1.8.0 of Laravel DataTables Editor the hook was not required
70+
// to return the $model.
71+
// In version 1.8.0+ the hook must return the $model instance:
72+
return $model;
4273
}
4374
```
4475

@@ -47,17 +78,21 @@ public function updated(Model $model, array $data) {
4778

4879
Remove action has the following event hooks:
4980

50-
- `deleting` event hook that is fired before deleting a new record.
81+
- `deleting` event hook that is fired before deleting a record.
5182
- `deleted` event hook that is fired after the record was deleted.
5283

5384
To use the event hook, just add the methods on your editor class.
5485

5586
```php
5687
public function deleting(Model $model, array $data) {
57-
return $data;
88+
// Record still exists in database. Code can be used to delete records from
89+
// child tables that don't specify cascade deletes on the foreign key
90+
// definition.
5891
}
5992

6093
public function deleted(Model $model, array $data) {
61-
return $data;
94+
// Record no longer exists in database, but $model instance still contains
95+
// data as it was before deleting. Any instance state mutation will be
96+
// preserved and returned in the 'data' array of the response.
6297
}
6398
```

0 commit comments

Comments
 (0)