rudexpunx's avatar

Storage links inconvenient behaviour?

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?

0 likes
2 replies
rudexpunx's avatar

Yeah, but it still doesn't make much sense to discard URL returned by the store() method and use extra static Storage method call to just generate correct URL, does it?

Please or to participate in this conversation.