You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
795 B
25 lines
795 B
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class QuestionResource extends JsonResource
|
|
{
|
|
public function toArray($request)
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'content' => $this->content,
|
|
'score' => $this->score,
|
|
'explanation' => $this->explanation,
|
|
'hint' => $this->hint,
|
|
'type' => [
|
|
'code' => $this->type->code ?? null,
|
|
'name' => $this->type->name ?? null,
|
|
],
|
|
'choices' => $this->when($this->type->code === 'multiple_choice', ChoiceResource::collection($this->choices)),
|
|
'blanks' => $this->when($this->type->code !== 'multiple_choice', BlankResource::collection($this->blanks)),
|
|
];
|
|
}
|
|
}
|
|
|