Get download link of a file in Laravel 5.7
How to generate a download link of a file uploaded by a user.
It depends on where you are storing the file, like example if you are storing the file in
public/uploads
than following will work if u are fetching it from database (single row)
<a href="/uploads/{{ $data->value }}"> Download </a>
My files are being stored in the Storage folder. When I use this method .
I get this error 'Sorry, the page you are looking for could not be found.
Create a symlink php artisan storage:link
@lawkunchi you can use the download response like so:
return response()->download($pathToFile);
I wanted to download a file uploaded by user and it was saved in the user's table. Below is my final code. Thank you!
public function download($id) {
$user = User::findorFail($id);
return Storage::download($user->file);
}
Route::get('download/{id}', [
'uses' => 'UserController@download',
'as' => 'file.download'
]);
Please or to participate in this conversation.