'404: Page Not Found, when trying to download file in Laravel 8
I am able to Upload files, But When I try to download PDF, it throws 404: Page Not Found..I don't know where I am wrong? My Controller is :
public function Download(Request $request,$path)
{
$path = public_path("dummy.pdf");
$headers = ['Content-Type: application/pdf'];
$fileName = time().'.pdf';
if (file_exists($path)) {
return Storage::download($path, $fileName, $headers);
} else {
echo('File not found.');
}
}//end of method
Routes Are :
Route::prefix('admin')->group(function(){
Route::get('/login',[AdminController::class,'Index'])->name('admin_login');
Route::post('/login/owner',[AdminController::class,'Login'])->name('admin.login');
Route::get('/dashboard',[AdminController::class,'Dashboard'])->name('admin.dashboard')->middleware('admin');
Route::get('/Logout',[AdminController::class,'AdminLogout'])->name('admin.logout')->middleware('admin');
/*--------------- File Upload Route---------*/
Route::get('/upload-file', [NoteController::class, 'createForm'])->name('upload-file');
Route::post('/upload-file', [NoteController::class, 'fileUpload'])->name('fileUpload');
Route::get('/notes', [NoteController::class, 'ViewNote'])->name('myNote');
Route::get('/download', [NoteController::class, 'Download'])->name('download');
And the View File is..
<tbody>
@foreach ($notes as $note)
<tr>
<td>{{ $note->path }}</td>
<td>{{ $note->user_type }}</td>
<td> {{ $note->description }}</td>
<td><a href="">View</a></td>
<td><a href="{{ route('download',$note->path) }}">Download</a></td>
</tr>
@endforeach
</tbody>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
