Skip to content

Commit ed15893

Browse files
committed
Snapshot resource 👥 org-user support
1 parent e6b1842 commit ed15893

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

‎app/Http/Resources/Portfolio/SnapshotResource.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Enums\Portfolio\Snapshot\SnapshotStateEnum;
66
use App\Models\Auth\CustomerUser;
7+
use App\Models\Auth\OrganisationUser;
78
use Illuminate\Http\Request;
89
use Illuminate\Http\Resources\Json\JsonResource;
910

@@ -27,13 +28,26 @@ public function toArray(Request $request): array
2728
}
2829

2930
$publisher = '';
30-
$publisher_avatar = null;
31+
$publisherAvatar = null;
3132
if ($snapshot->publisher_id) {
32-
/** @var CustomerUser $customerUser */
33-
$customerUser = $snapshot->publisher;
3433

35-
$publisher = $customerUser->user->contact_name;
36-
$publisher_avatar = $customerUser->user->avatarImageSources(48, 48);
34+
switch ($snapshot->publisher_type){
35+
case 'CustomerUser':
36+
/** @var CustomerUser $customerUser */
37+
$customerUser = $snapshot->publisher;
38+
39+
$publisher = $customerUser->user->contact_name;
40+
$publisherAvatar = $customerUser->user->avatarImageSources(48, 48);
41+
break;
42+
case 'OrganisationUser':
43+
/** @var OrganisationUser $organisationUser */
44+
$organisationUser = $snapshot->publisher;
45+
46+
$publisher = $organisationUser->contact_name;
47+
$publisherAvatar = $organisationUser->avatarImageSources(48, 48);
48+
}
49+
50+
3751
}
3852

3953

@@ -43,7 +57,7 @@ public function toArray(Request $request): array
4357
'published_until' => $snapshot->published_until,
4458
'layout' => $snapshot->layout,
4559
'publisher' => $publisher,
46-
'publisher_avatar' => $publisher_avatar,
60+
'publisher_avatar' => $publisherAvatar,
4761
'state' => match ($snapshot->state) {
4862
SnapshotStateEnum::LIVE => [
4963
'tooltip' => __('live'),

0 commit comments

Comments
 (0)