public function downloadFileMateri($idMateri) { $materi = Materi::findOrFail($idMateri); $materiTitle = $materi->title; $fileMateri = $materi->file; $pathTofile = public_path() . '/files/' . $fileMateri; //get the file location. $fileExtension = \File::extension($pathTofile); //get the file extension if (\File::exists($pathTofile)) { return response()->download($pathTofile, $materiTitle . "." . $fileExtension); } else { return "File tidak terdapat dalam sistem"; } }