Support the ongoing development of Laravel.io →
posted 1 year ago
Configuration

I'm pretty new to using Laravel and I'm experiencing an issue when developing my application; I'm not entirely sure if I'm just being an idiot and missing the obvious, but I can't seem to get the avatar to display when uploaded. When I upload an avatar, and then click save, it doesn't show, and instead shows the username (which is what I configured it to do if the avatar can't be found).

The issue is, I can see the avatar being saved into the appropriate field, but it just doesn't save. I've attatched the code below, but if there's anything missing that would be useful to see let me know.

// avatar.blade.php

@isset($user)
    <button class="flex flex-col items-center text-sm transition border-2 border-transparent rounded-full
    focus:outline-none focus:border-gray-300 hover:border-gray-300">
        <img src="{{ $attributes->merge(['class' => 'object-cover w-16 h-16 rounded-full']) }} src="{{ $user->profile_photo_url }}" alt="{{ $user->name() }}" />
    </button>
@else
<span class="inline-flex rounded-md">
    <button type="button" class="inline-flex items-center px-3 py-2 text-sm font-medium leading-4 text-gray-500 transition bg-white border
    border-transparent rounded-full hover:text-gray-700 focus:outline-none">
        {{ Auth::user()->name() }}
    </button>
</span>
@endisset

I'm calling the avatar in this portion of a different file:

        <div class="col-span-1">
            <x-user.avatar :user="$thread->author()" />
        </div>

When I upload an avatar as a user, it saves the avatar in both public/storage/profile-photos/ and also in storage/public/profile-photos and when I reupload it, it overwrites it and I can see this happening. If I right click and open image in tab on the place where the image should be, it shows: The requested resource /user/127.0.0.1:8000/storage/profile-photos/eVLjQB7JIPMDsUsg64ItaD4YWbk1fUYf73fjDAKh.png was not found on this server.

I assume this could be something to do with it? How can I debug this further to make it show?

Last updated by @lrzxft 1 year ago.
0

Try to run the php artisan storage:link maybe you have a permission issue.

0

Thank you for the suggestion, I tried running that and a link already exists, unfortunately, so I'm not sure that is the issue — does the rest of the code look like it should work?

Last updated 1 year ago.
0

The URL should be starting with http://127.0.0.1:8000/

Something is wrong with your path. What is the code generating the value for $user->profile_photo_url ?

0
Solution selected by @lrzxft

Ah, thank you @khatriafaz, I was missing the 'http' in .env file and this was causing the issue. Thank you!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Luke lrzxft Joined 15 Apr 2023

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.