@@ 9-37 (lines=29) @@ | ||
6 | use Tylercd100\Database\Eloquent\Traits\AutoCache; |
|
7 | use Tylercd100\Database\Eloquent\Traits\AutoValidate; |
|
8 | ||
9 | abstract class Model extends IlluminateModel |
|
10 | { |
|
11 | use AutoCache, AutoValidate; |
|
12 | ||
13 | /** |
|
14 | * A method best used to register Eloquent events when the model boots up |
|
15 | * @return void |
|
16 | */ |
|
17 | protected static function boot() |
|
18 | { |
|
19 | parent::boot(); |
|
20 | ||
21 | // Auto Validate |
|
22 | self::saving(function ($model) { |
|
23 | if (!$model->validate()) { |
|
24 | return false; |
|
25 | } |
|
26 | }); |
|
27 | ||
28 | // Auto Cache |
|
29 | static::saved(function ($model) { |
|
30 | $model->refresh(); |
|
31 | }, -1); |
|
32 | ||
33 | static::deleted(function ($model) { |
|
34 | $model->refresh(); |
|
35 | }, -1); |
|
36 | } |
|
37 | } |
|
38 |
@@ 9-37 (lines=29) @@ | ||
6 | use Tylercd100\Database\Eloquent\Traits\AutoCache; |
|
7 | use Tylercd100\Database\Eloquent\Traits\AutoValidate; |
|
8 | ||
9 | abstract class Pivot extends IlluminatePivot |
|
10 | { |
|
11 | use AutoCache, AutoValidate; |
|
12 | ||
13 | /** |
|
14 | * A method best used to register Eloquent events when the model boots up |
|
15 | * @return void |
|
16 | */ |
|
17 | protected static function boot() |
|
18 | { |
|
19 | parent::boot(); |
|
20 | ||
21 | // Auto Validate |
|
22 | self::saving(function ($model) { |
|
23 | if (!$model->validate()) { |
|
24 | return false; |
|
25 | } |
|
26 | }); |
|
27 | ||
28 | // Auto Cache |
|
29 | static::saved(function ($model) { |
|
30 | $model->refresh(); |
|
31 | }, -1); |
|
32 | ||
33 | static::deleted(function ($model) { |
|
34 | $model->refresh(); |
|
35 | }, -1); |
|
36 | } |
|
37 | } |
|
38 |