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

hamzaelmaghari's avatar

Laravel Fortify profile ( Urgent )

Hi devs, I have a request for you. I have a fortify app scafolding, I need to let users upload their profile photo, But I need it to be uploaded the same as jetstream. I want to access it by aliass such as:

<img src="Auth::user()->avatar_url" />

What I mean by the same as Jetstream is to generate a dynamic one if it's not exist using the service API (https://ui-avatars.com/). Thank You <3

0 likes
6 replies
alqahtani's avatar
Level 15

Here is the source code for the trait HasProfilePhoto which jetstream uses to handle the profile photo logic.

https://github.com/laravel/jetstream/blob/master/src/HasProfilePhoto.php

you can add these two methods to User model (and modify them to match your code) :

/**
     * Get the URL to the user's profile photo.
     *
     * @return string
     */
    public function getProfilePhotoUrlAttribute()
    {
        return $this->profile_photo_path
                    ? Storage::disk("public")->url($this->profile_photo_path)
                    : $this->defaultProfilePhotoUrl();
    }

    /**
     * Get the default profile photo URL if no profile photo has been uploaded.
     *
     * @return string
     */
    protected function defaultProfilePhotoUrl()
    {
        $name = trim(collect(explode(' ', $this->name))->map(function ($segment) {
            return $segment[0] ?? '';
        })->join(' '));

        return 'https://ui-avatars.com/api/?name='.urlencode($name).'&color=7F9CF5&background=EBF4FF';
    }

make sure that you append profile_photo_path to user model and to users database table. then you can use the photo like: <img src="auth()->user()->profile_photo_url" />

2 likes
aurelianspodarec's avatar

@martinbean Be nice Martin. No need to be bitter. He never said his questions are more important than anyone else either.

This is how people communicate, if you don't have anything good to say, don't say it.

3 likes
MichalOravec's avatar

Origin reply by @hamzaelmaghari

Be nice Martin. No need to be bitter. He never said his questions are more important than anyone else either. This is how people communicate, if you don't have anything good to say, don't say it.

Please or to participate in this conversation.