update tests
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\BaseModel;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Notification extends BaseModel
|
||||
@@ -28,12 +29,40 @@ class Notification extends BaseModel
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'scheduled_at' => 'datetime',
|
||||
'expires_at' => 'datetime',
|
||||
// If delivery_channels is JSON in DB:
|
||||
'delivery_channels' => 'array',
|
||||
'scheduled_at' => 'datetime',
|
||||
'expires_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* MySQL stores channels as SET('in_app','email','sms'); expose as array in PHP.
|
||||
*/
|
||||
protected function deliveryChannels(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: static function (?string $value): array {
|
||||
if ($value === null || $value === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
$trimmed = trim($value);
|
||||
if (str_starts_with($trimmed, '[')) {
|
||||
$decoded = json_decode($trimmed, true);
|
||||
|
||||
return is_array($decoded) ? array_values($decoded) : [];
|
||||
}
|
||||
|
||||
return array_values(array_filter(array_map('trim', explode(',', $value))));
|
||||
},
|
||||
set: static function ($value): string {
|
||||
if (is_array($value)) {
|
||||
return implode(',', array_values(array_filter(array_map('strval', $value))));
|
||||
}
|
||||
|
||||
return (string) $value;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Equivalent of legacy getActiveNotifications()
|
||||
* Active = scheduled_at <= now AND (expires_at is null OR expires_at > now)
|
||||
|
||||
Reference in New Issue
Block a user