I have got user’s images uploaded in Laravel storage. How can I access them and render them in a view?
The server is pointing all requests to/public
, so in order to show the image through Laravel blade view, we have to create a symlink in Mac / Windows that can point the url path from /storage
to /storage/app/public
folder.
For Mac users.
It is easy, just type below command (mentioned in Laravel Documentation: File Storage):
php artisan storage:link
Once the symbolic link has been created, you can create a URL to the files using the asset helper in view file:
echo asset('storage/image.jpg');
For Windows users.
You can use the mklink command, but first you need to access Command Prompt in Elevate Mode/Admin.
Windows Tips:
If you’re using a keyboard with Windows 10 or Windows 8, you can open an elevated Command Prompt quickly from the Power User Menu. Just press the WINDOWS and X keys together and then click on Command Prompt (Admin). Click Yes on any User Account Control messages that might appear.
After you open the Command Prompt (Admin), type below command:
mklink /j [project_folder_path]\public\storage [project_folder_path]\storage\app\public
If successfully created for Windows path, it will show below message:
Junction created for [project_folder_path]\public\storage <<===>> [project_folder_path]\storage\app\public
References List:
https://laravel.com/docs/5.7/filesystem#configuration
https://www.sevenforums.com/tutorials/278262-mklink-create-use-links-windows.html
https://www.lifewire.com/how-to-open-an-elevated-command-prompt-2618088