KTV/app/Http/Resources/RoomResource.php

28 lines
696 B
PHP
Raw Normal View History

2025-06-27 13:41:36 +08:00
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class RoomResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
2025-06-27 14:49:17 +08:00
$array = parent::toArray($request);
$array['started_at'] = $this->formatTaipei($this->started_at);
$array['ended_at'] = $this->formatTaipei($this->ended_at);
return $array;
}
protected function formatTaipei(?Carbon $value): ?string
{
return $value ? $value->timezone('Asia/Taipei')->format('Y-m-d H:i:s') : null;
2025-06-27 13:41:36 +08:00
}
}