-
app/Http/Resources/QuestionResource.php
Open in GitHubuse Illuminate\Http\Resources\Json\JsonResource; class QuestionResource extends JsonResource { public function toArray($request) { return [ 'id' => $this->id, 'title' => $this->title, 'description' => $this->description, 'category' => QuestionTypeResource::collection($this->whenLoaded('types')), 'choices' => QuestionChoiceResource::collection($this->whenLoaded('choice')), 'questionImage' => $this->questionImage, 'imagePath' => imagePath($this->imagePath), 'choiceImage' => $this->choiceImage, ]; } }
-
app/Http/Controllers/API/QuestionController.php
Open in GitHubuse App\Http\Controllers\Controller; use App\Http\Resources\QuestionResource; use App\Models\Question; use App\Services\QuizService; class QuestionController extends Controller { public function index(QuizService $questionService) { $questions = Question::with('choice')->get(); $questionService->testStore($questions); return QuestionResource::collection($questions); } // }