Reputation: 53
Hi im having an error while trying to download an uploaded file. Im using laravel 7. The error is 404 page not found and it might be because the directory do not match.
This is my store method in my controller:
public function store(Request $request){
$detalleTicket = new DetalleTicket();
if($request->file('file')){
$file = $request->file('file');
$filename = time().'.'.$file->getClientOriginalName();
$request->file->move('storage/', $filename);
$detalleTicket->file = $filename;
}
$detalleTicket->save();
Session::flash('success');
return redirect()->route('detalles-tickets.view');
}
This is my download method in my controller:
public function download($file){
return response()->download('storage/'.$file);
}
My directories are public->storage->(each file)
This is my route in web.php:
Route::get('/download/{file}', 'Backend\DetalleTicketController@download')->name('detalles-tickets.download');
And this is my dowload button:
<a title="Download" id="download" class="btn btn-sm btn-success"
href="/detalles-tickets/download/{{ $detalleTicket->file }}"><i
class="fa fa-download"></i></a>
Does anyone knows why as is click on the button i get 404 page not found?
Upvotes: 0
Views: 549
Reputation: 3440
@if($detalleTicket->file)
<a
title="Download"
id="download"
class="btn btn-sm btn-success"
href="{{ route('detalles-tickets.download', ['file' => $detalleTicket->file]) }}">
<i class="fa fa-download"></i>
</a>
@endif
Upvotes: 1