Laravel 5.4 cannot access img resource in public symlink subfolder

869 views Asked by At

I've created a sub folder for each user in local storage disk with this command:

if(! Storage::disk('public')->has("users/".$username."_".Auth::user()->id)){
    Storage::makeDirectory("public/users/".$username."_".Auth::user()->id);

and it works!

So now when i save a file, all goes in the user's folder, that is in:

storage/app/public/users/userX
storage/app/public/users/userY
etc.

Then I build a sim link with the command: php aritsan storage:link And it works.

But when im trying to serve the files i've allways nothing to serve! If im using code like:

Storage::url("$urlToFile");

where $urlToFile contains something like "public/users/userX/file.png"

it gives me back:

/storage/users/userX/file.png

and I cant use it even if i put function like assett() in front!

how can i solve it?

Thanks in advance!

3

There are 3 answers

5
Don't Panic On

According to the docs, you should access your images like: asset('storage/users/userX/file.png');, not public/users/userX/file.png as you are using.

3
Jithin Jose On

You have to set url in config/filesystem.php

'public' => [
    'driver' => 'local',
    'root' => storage_path('app/public'),
    'url' => env('APP_URL').'/storage',
    'visibility' => 'public',
],
1
Sletheren On

You can do it by Storage::disk('public')->get($url);