Files
nexusphp/app/Http/Resources/ExamUserResource.php

42 lines
1.2 KiB
PHP
Raw Normal View History

2021-04-25 02:12:14 +08:00
<?php
namespace App\Http\Resources;
use App\Models\Exam;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;
class ExamUserResource extends JsonResource
{
2021-04-26 20:37:17 +08:00
public $preserveKeys = true;
2021-04-25 02:12:14 +08:00
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'status' => $this->status,
'status_text' => $this->statusText,
'created_at' => format_datetime($this->created_at),
2021-04-26 20:37:17 +08:00
'progress' => $this->when($this->progress, $this->progress),
2021-04-27 19:13:32 +08:00
'progress_formatted' => $this->when($this->progress_formatted, $this->progress_formatted),
'begin' => format_datetime($this->begin),
'end' => format_datetime($this->end),
2021-04-27 19:13:32 +08:00
'uid' => $this->uid,
'exam_id' => $this->exam_id,
2021-05-15 02:13:33 +08:00
'is_done' => $this->is_done,
'is_done_text' => $this->is_done_text,
2021-04-25 02:12:14 +08:00
'user' => new UserResource($this->whenLoaded('user')),
'exam' => new ExamResource($this->whenLoaded('exam')),
];
}
2021-04-26 20:37:17 +08:00
2021-04-25 02:12:14 +08:00
}