RuinSain's avatar

How can i access files when i make a symbolic link from storage to public folder?

Hi, all. I am trying to figure out how can i work with files, display them to the public etc when i use the Storage facade. My steps were as follows:

  1. i run php artisan storage:link command. it worked and i can see a link folder called storage in the public directory.
  2. Now, when a user registers, i want to create a folder for that user to save all kind off stuff related to that user, as well as an avatar image for the profile. i am doing this like so: Storage::makeDirectory('/public/photos/profiles/'.$user->id);, and yes, it is successful.

Now, how can i upload a photo and use it from the public directory and display it? Thanks.

0 likes
6 replies
bobbybouwmann's avatar
Level 88

You can simply upload it to any of the two folders. They are linked to each other, so they are actually the same only on two locations.

Anyway, Laravel can help you with that using something like this

Storage::disk('public')->put('file.txt', 'Contents');

The public disk is the one which is symlinked. You can see all available storage places in the filesystems.php config file ;)

Now you only need to upload a photo and store it! You find find this bit of documentation interesting

Documentation: https://laravel.com/docs/5.5/filesystem#storing-files

1 like
RuinSain's avatar

Thank you so much, i know i am a noob :D

Please or to participate in this conversation.