34 lines
788 B
PHP
34 lines
788 B
PHP
<?php
|
|
|
|
namespace App\Http\Resources\Api\V2;
|
|
|
|
use App\Models\Question;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class QuestionResource extends JsonResource
|
|
{
|
|
|
|
/** @var Question */
|
|
private $question;
|
|
|
|
public function __construct(Question $question)
|
|
{
|
|
$this->question = $question;
|
|
}
|
|
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return array
|
|
*/
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
|
public function toArray($request)
|
|
{
|
|
return [
|
|
'id' => $this->question->id,
|
|
'question' => $this->question->question,
|
|
'answers' => new AnswersResource($this->question->answers)
|
|
];
|
|
}
|
|
}
|