Laravel display image from the storage
Laravel provides a powerful filesystem abstraction. The Laravel Flysystem integration provides simple to use drivers for working with local filesystems, Amazon S3, and Rackspace Cloud Storage. Even better, it's amazingly simple to switch between these storage options as the API remains the same for each system.
The filesystem configuration file is located at config/filesystems.php Within this file you may configure all of your "disks". Each disk represents a particular storage driver and storage location.
Example configurations for each supported driver are included in the configuration file. So, modify the configuration to reflect your storage preferences and credentials.
You may configure as many disks as you like, and may even have multiple disks that use the same driver.
The Public Disk
The public disk is intended for files that are going to be publicly accessible. By default, the public disk uses the local driver and stores these files in storage/app/public. To make them accessible from the web, you should create a symbolic link from public/storage to storage/app/public.
To create the symbolic link, you may use the storage: link Artisan command:
php artisan storage:link
The Local Driver
When using the local driver, all file operations are relative to the root directory defined in your configuration file.
By default, this value is set to the storage/app directory. Therefore, the following method would store a file in storage/app/file.txt:
By default, Laravel puts files in the directory
storage/app/public, which is not accessible from the outside web.
I often get this question, how to display storage folder images in shared hosting.
and this will symlink the path to the actual image stored path under storage folder - storage/app/public/images
But this is not the case on shared hosting. An image needs another path.
To overcome this problem, we will make a constant in the config/app.php
'file_path' => env('FILE_PATH', '/'),
and in the .env file, set its value according to the hosting (localhost or server)
Now you access the image
As simple as that...
Please share this article with your developer friends, it motivates us to make more tutorials like this.