Skip to content

Commit 4cdcaa6

Browse files
authored
Fix component pivot lookup (#312)
1 parent 5c18cf8 commit 4cdcaa6

File tree

8 files changed

+20
-18
lines changed

8 files changed

+20
-18
lines changed

src/Filament/Widgets/Feed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected function fetchFeed(string $uri, int $maxPosts = 5): array
6363
try {
6464
$response = Http::get($uri);
6565

66-
$xml = simplexml_load_string($response->getBody());
66+
$xml = simplexml_load_string($response->body());
6767

6868
$posts = [];
6969

src/Http/Resources/Component.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public function toAttributes(Request $request): array
3030
'human' => $this->updated_at?->diffForHumans(),
3131
'string' => $this->updated_at?->toDateTimeString(),
3232
],
33-
'pivot' => $this->when(isset($this->pivot) && isset($this->pivot->component_status), function () {
33+
'pivot' => $this->when($this->pivot?->component_status !== null, function () {
3434
return [
3535
'component_status' => [
36-
'human' => $this->pivot->component_status->getLabel(),
37-
'value' => $this->pivot->component_status->value,
36+
'human' => $this->pivot->component_status?->getLabel(),
37+
'value' => $this->pivot->component_status?->value,
3838
],
3939
];
4040
}),

src/Models/Incident.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class Incident extends Model
7373
'occurred_at' => 'datetime',
7474
];
7575

76-
/** @var array<string, string> */
76+
/** @var array<string, class-string> */
7777
protected $dispatchesEvents = [
7878
'created' => IncidentCreated::class,
7979
'deleted' => IncidentDeleted::class,

src/Models/Metric.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Metric extends Model
5555
'order' => 'int',
5656
];
5757

58-
/** @var array<string, string> */
58+
/** @var array<string, class-string> */
5959
protected $dispatchesEvents = [
6060
'created' => MetricCreated::class,
6161
'deleted' => MetricDeleted::class,

src/Models/MetricPoint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class MetricPoint extends Model
3535
'value' => 'float',
3636
];
3737

38-
/** @var array<string, string> */
38+
/** @var array<string, class-string> */
3939
protected $dispatchesEvents = [
4040
'created' => MetricPointCreated::class,
4141
'deleted' => MetricPointDeleted::class,

src/Models/Schedule.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,15 @@ protected function status(): Attribute
8181
/**
8282
* Get the components affected by this schedule.
8383
*
84-
* @return BelongsToMany<Component, $this>
84+
* @return BelongsToMany<Component, $this, ScheduleComponent>
8585
*/
8686
public function components(): BelongsToMany
8787
{
8888
return $this->belongsToMany(
8989
Component::class,
9090
'schedule_components',
91-
)->withPivot(['component_status'])
91+
)->using(ScheduleComponent::class)
92+
->withPivot(['component_status'])
9293
->withTimestamps();
9394
}
9495

src/Models/ScheduleComponent.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,35 @@
33
namespace Cachet\Models;
44

55
use Cachet\Database\Factories\ScheduleComponentFactory;
6+
use Cachet\Enums\ComponentStatusEnum;
67
use Carbon\Carbon;
78
use Illuminate\Database\Eloquent\Factories\Factory;
89
use Illuminate\Database\Eloquent\Factories\HasFactory;
9-
use Illuminate\Database\Eloquent\Model;
1010
use Illuminate\Database\Eloquent\Relations\BelongsTo;
11+
use Illuminate\Database\Eloquent\Relations\Pivot;
1112

1213
/**
1314
* @property int $id
1415
* @property int $schedule_id
1516
* @property int $component_id
16-
* @property int $component_status
17+
* @property ?ComponentStatusEnum $component_status
1718
* @property ?Carbon $created_at
1819
* @property ?Carbon $updated_at
1920
* @property Schedule $schedule
2021
* @property Component $component
2122
*
2223
* @method static ScheduleComponentFactory factory($count = null, $state = [])
2324
*/
24-
class ScheduleComponent extends Model
25+
class ScheduleComponent extends Pivot
2526
{
27+
protected $table = 'schedule_components';
28+
2629
/** @use HasFactory<ScheduleComponentFactory> */
2730
use HasFactory;
2831

29-
/** @var list<string> */
30-
protected $fillable = [
31-
'schedule_id',
32-
'component_id',
33-
'component_status',
32+
/** @var array<string, string> */
33+
protected $casts = [
34+
'component_status' => ComponentStatusEnum::class,
3435
];
3536

3637
/**

src/Models/Subscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Subscriber extends Model
3636
'verified_at' => 'datetime',
3737
];
3838

39-
/** @var array<string, string> */
39+
/** @var array<string, class-string> */
4040
protected $dispatchesEvents = [
4141
'created' => SubscriberCreated::class,
4242
'deleted' => SubscriberUnsubscribed::class,

0 commit comments

Comments
 (0)