forked from knuckleswtf/scribe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestUserApiResource.php
44 lines (38 loc) · 1.15 KB
/
TestUserApiResource.php
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
40
41
42
43
44
<?php
namespace Knuckles\Scribe\Tests\Fixtures;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @mixin \Knuckles\Scribe\Tests\Fixtures\TestUser
*/
class TestUserApiResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function toArray($request)
{
if($request->route()->named('someone')) {
return ['someone' => true];
}
$result = [
'id' => $this->id,
'name' => $this->first_name . ' ' . $this->last_name,
'email' => $this->email,
'children' => $this->whenLoaded('children', function () {
return TestUserApiResource::collection($this->children);
}),
'pets' => $this->whenLoaded('pets', function () {
return TestPetApiResource::collection($this->pets);
}),
];
if ($this['state1'] && $this['random-state']) {
$result['state1'] = $this['state1'];
$result['random-state'] = $this['random-state'];
}
return $result;
}
}