| Conditions | 8 |
| Paths | 1 |
| Total Lines | 31 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | protected static function boot(): void |
||
| 11 | { |
||
| 12 | parent::boot(); |
||
| 13 | |||
| 14 | static::saved(function($model) { |
||
| 15 | $shouldSave = false; |
||
| 16 | |||
| 17 | foreach ($model->attachments as $attachment) { |
||
| 18 | if (!$attachment->isUploaded()) { |
||
| 19 | $shouldSave = true; |
||
| 20 | |||
| 21 | $model = $attachment->saved($model); |
||
| 22 | } |
||
| 23 | } |
||
| 24 | |||
| 25 | if ($shouldSave) { |
||
| 26 | $model->save(); |
||
| 27 | } |
||
| 28 | }); |
||
| 29 | |||
| 30 | static::deleted(function($model) { |
||
| 31 | if (!$model->hasGlobalScope(SoftDeletingScope::class) or $model->isForceDeleting()) { |
||
| 32 | foreach ($model->attachments as $attachment) { |
||
| 33 | $attachment->deleted(); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | }); |
||
| 37 | |||
| 38 | static::retrieved(function($model) { |
||
| 39 | foreach ($model->attachments as $attachment) { |
||
| 40 | $attachment->setOutput($model); |
||
| 41 | } |
||
| 45 |