-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserResource.php
More file actions
39 lines (32 loc) · 1.32 KB
/
UserResource.php
File metadata and controls
39 lines (32 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\Resource;
use Illuminate\Support\Collection;
class UserResource extends Resource
{
public function toArray($request)
{
$user = [
'id' => $this->id,
'email' => $this->email,
'activated' => $this->activated,
'password_updated_at' => ($this->password_updated_at) ? $this->password_updated_at->format('c') : null,
'confirmed' => $this->confirmed,
'last_logged_in_at' => ($this->last_logged_in_at) ? $this->last_logged_in_at->format('c') : null,
'created_at' => $this->created_at->format('c'),
'user_profile' => UserProfileResource::make($this->userProfile),
'confirmed_role' => $this->confirmed_role,
'can_access_legacy_whatnow' => (bool) $this->can_access_legacy_whatnow,
'can_access_preparedness_v2' => (bool) $this->can_access_preparedness_v2,
];
$roles = $this->whenLoaded('roles');
if($roles instanceof Collection) {
$user['role'] = RoleResource::make($roles->first());
}
$orgs = $this->whenLoaded('organisations');
if ($orgs instanceof Collection) {
$user['organisations'] = $orgs->pluck('organisation_code');
}
return $user;
}
}