Skip to content

Commit c4a27cd

Browse files
committed
improved the file resource
1 parent 6e84c13 commit c4a27cd

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/Http/Resources/File.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@ class File extends JsonResource
99
{
1010
public function toArray($request)
1111
{
12-
return [
13-
'id' => $this->id,
14-
'name' => $this->original_name,
15-
'size' => $this->size,
16-
'mimeType' => $this->mime_type,
17-
'type' => $this->type(),
18-
'owner' => new User($this->whenLoaded('createdBy')),
19-
'isDestroyable' => $this->destroyableBy($request->user()),
20-
'isShareable' => $this->shareableBy($request->user()),
21-
'isViewable' => $this->viewableBy($request->user()),
22-
'createdAt' => $this->created_at->toDatetimeString(),
23-
];
12+
return $this->id
13+
? [
14+
'id' => $this->id,
15+
'name' => $this->original_name,
16+
'size' => $this->size,
17+
'mimeType' => $this->mime_type,
18+
'type' => $this->type(),
19+
'owner' => new User($this->whenLoaded('createdBy')),
20+
'isDestroyable' => $this->destroyableBy($request->user()),
21+
'isShareable' => $this->shareableBy($request->user()),
22+
'isViewable' => $this->viewableBy($request->user()),
23+
'createdAt' => $this->created_at->toDatetimeString(),
24+
]
25+
: null;
2426
}
2527
}

0 commit comments

Comments
 (0)