28 lines
696 B
PHP
28 lines
696 B
PHP
<?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
|
|
{
|
|
$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;
|
|
}
|
|
}
|