diff --git a/src/Filament/Widgets/Feed.php b/src/Filament/Widgets/Feed.php index 60415a84..3175e5cc 100644 --- a/src/Filament/Widgets/Feed.php +++ b/src/Filament/Widgets/Feed.php @@ -63,7 +63,7 @@ protected function fetchFeed(string $uri, int $maxPosts = 5): array try { $response = Http::get($uri); - $xml = simplexml_load_string($response->getBody()); + $xml = simplexml_load_string($response->body()); $posts = []; diff --git a/src/Http/Resources/Component.php b/src/Http/Resources/Component.php index 59f4f933..8eafffc1 100644 --- a/src/Http/Resources/Component.php +++ b/src/Http/Resources/Component.php @@ -30,11 +30,11 @@ public function toAttributes(Request $request): array 'human' => $this->updated_at?->diffForHumans(), 'string' => $this->updated_at?->toDateTimeString(), ], - 'pivot' => $this->when(isset($this->pivot) && isset($this->pivot->component_status), function () { + 'pivot' => $this->when($this->pivot?->component_status !== null, function () { return [ 'component_status' => [ - 'human' => $this->pivot->component_status->getLabel(), - 'value' => $this->pivot->component_status->value, + 'human' => $this->pivot->component_status?->getLabel(), + 'value' => $this->pivot->component_status?->value, ], ]; }), diff --git a/src/Models/Incident.php b/src/Models/Incident.php index 4e624807..f5f9c347 100644 --- a/src/Models/Incident.php +++ b/src/Models/Incident.php @@ -73,7 +73,7 @@ class Incident extends Model 'occurred_at' => 'datetime', ]; - /** @var array */ + /** @var array */ protected $dispatchesEvents = [ 'created' => IncidentCreated::class, 'deleted' => IncidentDeleted::class, diff --git a/src/Models/Metric.php b/src/Models/Metric.php index 57132910..f30c43dd 100644 --- a/src/Models/Metric.php +++ b/src/Models/Metric.php @@ -55,7 +55,7 @@ class Metric extends Model 'order' => 'int', ]; - /** @var array */ + /** @var array */ protected $dispatchesEvents = [ 'created' => MetricCreated::class, 'deleted' => MetricDeleted::class, diff --git a/src/Models/MetricPoint.php b/src/Models/MetricPoint.php index 81c14580..fd2e1007 100644 --- a/src/Models/MetricPoint.php +++ b/src/Models/MetricPoint.php @@ -35,7 +35,7 @@ class MetricPoint extends Model 'value' => 'float', ]; - /** @var array */ + /** @var array */ protected $dispatchesEvents = [ 'created' => MetricPointCreated::class, 'deleted' => MetricPointDeleted::class, diff --git a/src/Models/Schedule.php b/src/Models/Schedule.php index e4caab9c..961e01c1 100644 --- a/src/Models/Schedule.php +++ b/src/Models/Schedule.php @@ -81,14 +81,15 @@ protected function status(): Attribute /** * Get the components affected by this schedule. * - * @return BelongsToMany + * @return BelongsToMany */ public function components(): BelongsToMany { return $this->belongsToMany( Component::class, 'schedule_components', - )->withPivot(['component_status']) + )->using(ScheduleComponent::class) + ->withPivot(['component_status']) ->withTimestamps(); } diff --git a/src/Models/ScheduleComponent.php b/src/Models/ScheduleComponent.php index d34c7f98..cd491a63 100644 --- a/src/Models/ScheduleComponent.php +++ b/src/Models/ScheduleComponent.php @@ -3,17 +3,18 @@ namespace Cachet\Models; use Cachet\Database\Factories\ScheduleComponentFactory; +use Cachet\Enums\ComponentStatusEnum; use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\HasFactory; -use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\Pivot; /** * @property int $id * @property int $schedule_id * @property int $component_id - * @property int $component_status + * @property ?ComponentStatusEnum $component_status * @property ?Carbon $created_at * @property ?Carbon $updated_at * @property Schedule $schedule @@ -21,16 +22,16 @@ * * @method static ScheduleComponentFactory factory($count = null, $state = []) */ -class ScheduleComponent extends Model +class ScheduleComponent extends Pivot { + protected $table = 'schedule_components'; + /** @use HasFactory */ use HasFactory; - /** @var list */ - protected $fillable = [ - 'schedule_id', - 'component_id', - 'component_status', + /** @var array */ + protected $casts = [ + 'component_status' => ComponentStatusEnum::class, ]; /** diff --git a/src/Models/Subscriber.php b/src/Models/Subscriber.php index 4694713f..3982e832 100644 --- a/src/Models/Subscriber.php +++ b/src/Models/Subscriber.php @@ -36,7 +36,7 @@ class Subscriber extends Model 'verified_at' => 'datetime', ]; - /** @var array */ + /** @var array */ protected $dispatchesEvents = [ 'created' => SubscriberCreated::class, 'deleted' => SubscriberUnsubscribed::class,