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,
|
2021-04-26 20:37:17 +08:00
|
|
|
'created_at' => formatDatetime($this->created_at),
|
|
|
|
|
'progress' => $this->when($this->progress, $this->progress),
|
|
|
|
|
'begin' => formatDatetime($this->begin),
|
|
|
|
|
'end' => formatDatetime($this->end),
|
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
|
|
|
}
|