| Total Complexity | 7 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 8 | class NotificationEvent extends Model |
||
| 9 | { |
||
| 10 | protected $table = 'notifier_events'; |
||
| 11 | protected $fillable = [ |
||
| 12 | 'group', |
||
| 13 | 'name', |
||
| 14 | 'key', |
||
| 15 | 'description', |
||
| 16 | 'is_active', |
||
| 17 | 'settings', |
||
| 18 | ]; |
||
| 19 | |||
| 20 | protected $casts = [ |
||
| 21 | 'is_active' => 'boolean', |
||
| 22 | 'settings' => 'array', |
||
| 23 | ]; |
||
| 24 | |||
| 25 | protected static function boot() |
||
| 26 | { |
||
| 27 | parent::boot(); |
||
| 28 | |||
| 29 | static::saving(function ($model) { |
||
| 30 | // Check if settings column exists before trying to save |
||
| 31 | try { |
||
| 32 | $columns = Schema::getColumnListing($model->getTable()); |
||
| 33 | if (!in_array('settings', $columns)) { |
||
| 34 | // Remove settings from attributes if no column |
||
| 35 | unset($model->attributes['settings']); |
||
| 36 | unset($model->original['settings']); |
||
| 37 | } elseif (empty($model->settings) || $model->settings === []) { |
||
| 38 | |||
| 39 | $model->settings = null; |
||
| 40 | } |
||
| 41 | } catch (\Exception $e) { |
||
| 42 | // If we cant check, just unset it to be safe |
||
| 43 | unset($model->attributes['settings']); |
||
| 44 | } |
||
| 45 | }); |
||
| 46 | } |
||
| 47 | |||
| 48 | public function templates(): HasMany |
||
| 49 | { |
||
| 50 | return $this->hasMany(NotificationTemplate::class, 'event_key', 'key'); |
||
| 51 | } |
||
| 52 | |||
| 53 | public function preferences(): HasMany |
||
| 56 | } |
||
| 57 | } |
||
| 58 |