public function download(Request $request, $examId) { if (null === $request->user()) { throw new AccessDeniedHttpException(); } else { if (null === ($exam = Exam::find($examId))) { throw new NotFoundHttpException(); } } $exam->increment('downloads'); Event::_create('events.user', $request->user(), 'user.download', collect(['target' => 'courses.exams', 'identify' => $examId])); return response()->download(storage_path('uploads/courses/exams') . '/' . $exam->getAttribute('file_path'), $exam->getAttribute('file_name'), ['Content-Length' => $exam->getAttribute('file_size'), 'Content-Type' => $exam->getAttribute('file_type')]); }