https://laravel.com/docs/9.x/filesystem#file-urls
Example:
return Storage::disk('public')->url('cover/cover.jpg');
Can anyone explain, why are storage links so inconvenient?
If I want to upload a file and save path to my DB for a future use, I need to replace directory in the returned path because of (default) public -> storage linking.
The issue basically is that when saving, I am supposed to provide app/storage/... path while when requesting, Laravel will look into app/public/storage/..., however the store method returns the original path.
So
// public/covers/cover.jpg
$path = $request->file('image')->store('public/covers');
// http://mysite.test/public/covers/cover.jpg
$url = asset($path);
But the file is by default accessible at
http://mysite.test/storage/covers/cover.jpg
So I basically need to do one extra step (nasty hack) to make it work without changing default config
$path = str_replace('public', 'storage', $request->file('image')->store('public/covers'));
Am I missing something?
Please or to participate in this conversation.