I have got user\'s avatars uploaded in Laravel storage. How can I access them and render them in a view?
The server is pointing all requests to /public,
It is good to save all the private images and docs in storage directory then you will have full control over file ether you can allow certain type of user to access the file or restrict.
Make a route/docs and point to any controller method:
public function docs() {
//custom logic
//check if user is logged in or user have permission to download this file etc
return response()->download(
storage_path('app/users/documents/4YPa0bl0L01ey2jO2CTVzlfuBcrNyHE2TV8xakPk.png'),
'filename.png',
['Content-Type' => 'image/png']
);
}
When you will hit localhost:8000/docs file will be downloaded if any exists.
The file must be in root/storage/app/users/documents directory according to above code, this was tested on Laravel 5.4.