Display image that are stored in public folder in Laravel 8
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Mastering Media Display in Laravel: Troubleshooting Images in the Public Folder
Hello developers! Dealing with file uploads and asset display in a web framework like Laravel can sometimes lead to frustrating roadblocks. You’ve successfully stored your images in the public directory, but they refuse to display? This is an extremely common issue, usually stemming from a small misunderstanding of how Laravel constructs public URLs or basic server permissions.
As a senior developer, I’ve seen countless scenarios like this. Today, we are going to debug exactly why your images aren't showing up, review the code you provided, and implement the most robust, scalable way to handle file storage in Laravel.
The Root Cause: Understanding Laravel Asset Handling
The core of your problem likely lies in how you are generating the path within your Blade file, or potentially a server permission issue. Let’s break down the implementation you shared.
Your Blade snippet uses the asset() helper:
<td class="image-display">
<img style="width:70px;" src="{{ asset('public/Image/'.$key->image) }}">
</td>
The asset() helper is designed to generate URLs for files stored in the public directory. When you use asset('public/Image/filename'), Laravel prepends the public path root (public/) to your specified path, resulting in a URL like /public/public/Image/filename. This double-pathing is often the source of the failure when dealing with assets stored directly under the public folder.
The Correct Way to Reference Public Assets
To correctly reference files within the public directory, you should omit the leading public/ segment inside the asset() call, as Laravel automatically handles resolving paths relative to the public root.
Correction Example:
If your images are stored at public/Image/my_photo.jpg, the correct way to reference it is:
<img style="width:70px;" src="{{ asset('Image/'.$key->image) }}">
This generates the correct URL, such as /Image/my_photo.jpg. This principle of managing public assets correctly is fundamental when building any application on Laravel, and understanding these file paths is key to mastering system architecture, much like learning about data relationships in Eloquent models from resources like laravelcompany.com.
Reviewing the File Upload Logic (Controller)
Let's look at your controller logic for storing the files:
if($request->hasFile('image'))
{
$file = $request->file('image');
$extension = $file->getClientOriginalExtension();
$filename = time() . '.' . $extension;
// Storing directly to public/Image/
$file->move('public/Image/', $filename);
$post->image = $filename;
}
While this method can work, it bypasses Laravel’s built-in file management tools and relies heavily on manual path construction. A more robust approach involves using the Storage facade, which abstracts away the tedious file system interactions and ensures consistency, especially when dealing with different storage drivers (like local disk, S3, etc.).
Implementing Best Practices with the Storage Facade
For cleaner, safer, and more maintainable code, you should leverage the Illuminate\Support\Facades\Storage class. This approach is highly recommended for any serious Laravel project, promoting better separation of concerns—a core principle in solid software development practices detailed on laravelcompany.com.
Here is how you would refactor your controller to use the Storage facade:
use Illuminate\Support\Facades\Storage;
public function store(Request $request)
{
$validated = $this->validate($request, [
'title' => 'required',
'image' => 'required',
// ... other validations
'image.*' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048'
]);
if ($request->hasFile('image')) {
// Store the file on the local disk configured in config/filesystems.php
$path = $request->file('image')->store('images', 'public');
// $path will be something like 'images/1678880000.jpg'
// Save the path to the database, not just the filename
$post->image = $path;
}
// ... rest of your saving logic
}
Final Checklist and Conclusion
If you implement the path correction in your Blade file (asset('Image/'.$key->image)) and ensure that your server has write permissions on the public/Image directory, your images should display correctly.
Remember, when dealing with file systems in Laravel, always prioritize using the provided facades like Storage. This ensures your application remains flexible, secure, and scalable as you grow. Keep building great applications, and don't hesitate to dive deeper into mastering these powerful tools!