guessing-miniprogram/app/Http/Resources/Api/ActivityGameResource.php

40 lines
1.2 KiB
PHP

<?php
namespace App\Http\Resources\Api;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Http\Response;
class ActivityGameResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'activity_id' => $this->activity_id,
'name' => $this->name,
'home_field' => $this->home_field ??'',
'home_logo' => $this->home_logo ??'',
'away' => $this->away ??'',
'away_logo' => $this->away_logo ??'',
'game_at' => $this->game_at->format('Y-m-d H:i'),
'little_game_at' => $this->game_at->format('H:i'),
'game_day' => $this->game_at->format('Y-m-d'),
'game_at_comparison_now' => now()->gte($this->game_at),
'mark' => $this->mark,
'has_guess' => !$this->logs->isEmpty() ? ($this->logs[0]->score):false,
'state' => $this->state,
];
}
public function with($request)
{
return ['code' => Response::HTTP_OK, 'message' => ''];
}
}