Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

TylerW's avatar

Proper Way To Retrieve Avatar Images?

I know a lot of threads have been made about this in the past, but after much searching I cannot find one that is recent and adequately explains how to retrieve images you have saved to storage.

I am uploading avatar images to to the avatars folder, which means they are being stored in storage/app/avatars. I am then adding the path returned by the store method to a column in the user database. This value looks like avatars/j4yZcfzSSJnRONYKaiTUZTrQp5UaDQfSSnrZ5i8G.jpeg.

Simply put, how do I access the URL to this image such that I can display the image? Some threads say to store the file in a different directory, some say to create a link of some sort. I want to know how to do this the right way because this is a task I do quite often. After scouring the documentation, I cannot seem to find what I'm looking for in simple enough terms.

0 likes
5 replies
Cronix's avatar

First, you'd need to create a symlink between your storage and public dirs.

php artisan storage:link https://laravel.com/docs/5.6/filesystem#configuration

Then you'd just output them like normal, pretending they are in the "storage" dir of /public.

<img src="/storage/avatars/j4yZcfzSSJnRONYKaiTUZTrQp5UaDQfSSnrZ5i8G.jpeg">

or

<img src="{{ asset('storage/avatars/j4yZcfzSSJnRONYKaiTUZTrQp5UaDQfSSnrZ5i8G.jpeg') }}">
Tarasovych's avatar

May be helpful: Storage::disk('public')->url('avatars/your_image.jpeg') (if you've linked storage to public).

TylerW's avatar

Hey @Cronix , thanks again for your help.

I did read about that solution, but it says it is not possible to use on most shared hosting platforms. This is a great concern for me because most likely the website I am working on will be running on shared hosting.

Why is it the case that this will not work on shared hosting? I mean, a folder is a folder and if the folder is located on my server it seems like it should be able to access it. Perhaps I'm misunderstanding the storage aspect of Laravel.

And in the case that it cannot be used on shared hosting, what alternative would you recommend? Simply storing the file in the public folder?

Cronix's avatar
Cronix
Best Answer
Level 67

It depends on the hosting service. Some shared hosting will allow symlinks, others won't. It could be a massive security hole if the host lets you use symlinks that reference something in another users space.

Another option would be to use a S3 bucket for your uploads so they aren't even stored on your server. I'd probably lean towards this route anyway.

Another option is to change your storage for avatars.

'disks' => [
   'avatar' => [
       'driver' => 'local',
       'root'   => public_path() . '/avatars',
       'url' => config('app.url') . '/avatars',
       'visibility' => 'public',
    ]
]

and save to the "avatar" disk instead of the "public" disk. It will store in /public/avatars instead of /storage/app/avatars.

1 like
TylerW's avatar

@Cronix Sorry for the late reply, but this appears to be exactly the answer I was looking for. I'll report back if I run into any issues, but for now I will mark you as correct answer.

Please or to participate in this conversation.