public function show($courseId = null) { if (null === $courseId || null === ($course = Course::with(['department'])->find($courseId))) { throw new NotFoundHttpException(); } return response()->json($course); }
public function index($courseId) { $course = Course::with(['exams' => function ($query) { $query->orderBy('semester_id', 'desc')->orderBy('downloads', 'desc'); }])->find($courseId, ['id']); if (null === $course) { throw new NotFoundHttpException(); } $exams = $course->getRelation('exams')->map(function ($exam) { $exam->setAttribute('uploaded_at', $this->convertTimeFieldToHumanReadable($exam->getAttribute('created_at'))); return $exam; }); return response()->json($exams); }