| Total Complexity | 7 |
| Total Lines | 26 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | class RolePromotionObserver |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Handle the RolePromotion "saving" event. |
||
| 12 | * Automatically disable promotion if end date has passed |
||
| 13 | */ |
||
| 14 | public function saving(RolePromotion $promotion): void |
||
| 15 | { |
||
| 16 | // If the promotion has an end date that has passed, automatically disable it |
||
| 17 | if ($promotion->end_date && Carbon::now()->gt($promotion->end_date)) { |
||
| 18 | $promotion->is_active = false; |
||
| 19 | } |
||
| 20 | } |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Handle the RolePromotion "retrieved" event. |
||
| 24 | * This helps ensure that when a promotion is loaded from the database, |
||
| 25 | * we check if it should be disabled |
||
| 26 | */ |
||
| 27 | public function retrieved(RolePromotion $promotion): void |
||
| 34 | } |
||
| 35 | } |
||
| 38 |