Laravel get public url for file stored in storage public folder
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Mastering Public File Access in Laravel: Solving the Storage URL Mystery
As a senior developer working with the Laravel ecosystem, one of the most common points of confusion—and frustration—is correctly exposing files stored within the application's storage directory for public access. Many developers follow the setup steps but run into 404 errors, as you experienced, because they are missing a crucial step in the deployment process.
This post will diagnose why your attempt to generate a public URL for a file in the storage/app/public folder failed and provide the definitive, best-practice solution for serving assets publicly in a Laravel application.
The Problem: Why Storage::url() Fails for Public Assets
You have correctly configured your filesystem driver to point to the storage location, and you are attempting to use $fileDTO->filePath = Storage::url($fileName);. However, when this URL is accessed via the browser (e.g., http://localhost:8082/crm-api/public/storage/filename.txt), you receive a 404 error.
The reason for this discrepancy lies in how Laravel structures its file serving versus how the web server maps URLs to physical files. When you use the filesystem driver, Laravel manages the internal pathing, but it does not automatically create the necessary symbolic link that connects the application's public web root directly to the stored files. The Storage::url() method generates a path relative to the storage configuration, which often doesn't align with the actual publicly accessible URL structure unless explicitly linked.
The Solution: Linking the Storage Disk to the Public Directory
To make files stored in the disk accessible via a web URL, you must create a symbolic link from the configured storage directory into the public directory of your application. This is a standard practice recommended by the Laravel team for managing public asset access efficiently.
Step 1: Verify Your Configuration
Ensure your configuration correctly maps the storage to a publicly accessible path. In your config/filesystems.php file, you should define a disk (or use the default public disk) and ensure the url setting is appropriate. While your example used the local driver pointing to storage_path('app/public'), the key step is the linking mechanism itself.
Step 2: Execute the Symbolic Link Command
The magic happens when you instruct the operating system to create a shortcut (a symbolic link) from the storage folder into the public folder. Run this command in your terminal within your project root:
php artisan storage:link
This single command creates a symbolic link named storage inside your public directory, pointing directly to storage/app/public. This tells the web server (Apache/Nginx) exactly where to look when a request comes in for URLs starting with /storage/.
Step 3: Accessing the File Correctly
After running the link command, Laravel ensures that any URL generated using the storage facade correctly resolves through this public mapping.
When you use Storage::url($fileName), it generates a path relative to the configured disk root. When combined with the symbolic link established by storage:link, Laravel automatically handles the translation into the correct public web path.
If your file is named 381787c3ad1442cc882ee427e93af805.txt:
The resulting public URL will be constructed as:[APP_URL]/storage/[filename]
For your example, this results in:http://localhost:8082/crm-api/public/storage/381787c3ad1442cc882ee427e93af805.txt
This structure is now correctly recognized by your web server, resolving the 404 error and allowing you to successfully retrieve the file. This approach demonstrates how powerful Laravel’s abstraction layer is in managing complex file system interactions behind simple, clean methods.
Conclusion: Embracing Laravel's Ecosystem
Understanding the relationship between internal storage paths and external public URLs is fundamental to building robust Laravel applications. Relying solely on the filesystem driver settings without executing the necessary linking command leads to common deployment errors like 404s. Always remember that Laravel provides powerful tools, such as the Storage facade (as seen in documentation on laravelcompany.com), and using these tools correctly by adhering to established conventions ensures your application is both functional and secure. By mastering these foundational steps, you move from debugging errors to architecting seamless file delivery systems.