Whats the best way to solve this?
@liamseys The “best way” to solve your problem is to just use Laravel’s filesystem component as intended.
The Storage façade (and underlying filesystem component) is meant to give you disk-agnostic access to files. It means you should be able to use the same code regardless of what disk driver you’re using, be it local, S3, or anything else.
It’s unclear whether these are user-uploaded images or just generic application images. If they’re user-uploaded images, then you shouldn’t be uploading them to your /public folder. This folder should be version-controlled and for application images only. If users are randomly dropping files in this folder, then your website is going to be out of sync with your source repository (Git or whatever).
If these are user-uploaded images, then store them in your /storage folder and serve appropriately-sized thumbnails. You don’t want to be serving 4 MB images just because that’s what a user uploaded.
So, back to the problem at hand. If you use the Storage façade properly then you can switch what driver it uses by setting the FILESYSTEM_DRIVER environment variable. You can set it to local in your local environment, and s3 on your production server, and your code won’t need to change. Then when you want to generate a URL to a file, you can use the appropriate method:
<img src="{{ Storage::url($imagePath) }}">