php artisan storage:link (as per the documentation), a symlink between
storage/app/public is created. I realise this is by design, but it leads to some very confusing behaviour not covered by the documentation.
For example: If you saveAs a file to an
avatars directory, it's stored in:
storage/app/avatars and the path returned (for database storage) is:
avatars/filename.jpg. This is outside the symlink. Instead we need to tell it saveAs to
storage/app/public/avatars (which results in a path returned for database storage being:
According to the documentation, all we need to do to refer to this file is
asset('avatars/filename.jpg') in our code, but that doesn't work. (And neither does the string we stored:
asset('public/avatars/filename.jpg').) Instead it needs to be
Which means we need to do a
str_replace('public', 'storage', asset($filename)) to make an application work as per the documentation's instructions :-/
I assume I'm doing something wrong, but this so very confusing! Is there a better way to deal with this behaviour?