forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResultResource.php
More file actions
38 lines (35 loc) · 1.45 KB
/
ResultResource.php
File metadata and controls
38 lines (35 loc) · 1.45 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
<?php
namespace App\Http\Resources\V1;
use App\Helpers\Bitrate;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ResultResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'service' => $this->service,
'ping' => $this->ping,
'download' => $this->download,
'upload' => $this->upload,
'download_bits' => $this->when($this->download, fn (): int|float => Bitrate::bytesToBits($this->download)),
'upload_bits' => $this->when($this->upload, fn (): int|float => Bitrate::bytesToBits($this->upload)),
'download_bits_human' => $this->when($this->download, fn (): string => Bitrate::formatBits(Bitrate::bytesToBits($this->download)).'ps'),
'upload_bits_human' => $this->when($this->upload, fn (): string => Bitrate::formatBits(Bitrate::bytesToBits($this->upload)).'ps'),
'benchmarks' => $this->benchmarks,
'healthy' => $this->healthy,
'status' => $this->status,
'scheduled' => $this->scheduled,
'comments' => $this->comments,
'data' => $this->data,
'created_at' => $this->created_at->toDateTimestring(),
'updated_at' => $this->updated_at->toDateTimestring(),
];
}
}