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

TerrePorter's avatar

getProfilePhotoUrlAttribute not using jetstream

Hey,

I got a weird one. I received the error message.

Call to undefined method App\Models\User::getProfilePhotoUrlAttribute()

I traced this back to JetStream, but I didn't install JetStream and I only found one reference to it at https://jetstream.laravel.com/features/profile-management.html and another on an old issue post where all they did was tell that person to post on the forums.

I do find it funny that on the profile-management page, they say (Laravel\Jetstream\HasProfilePhoto) "This trait contains methods such as updateProfilePhoto, getProfilePhotoUrlAttribute, defaultProfilePhotoUrl, and profilePhotoDisk which may all be overwritten by your own App\Models\User class if you need to customize their behavior." but that function doesn't exist on the trait - at least as far as I can find.

I didn't find it on the GitHub source for JetStream either and to top that off I did a file search on my own code, and didn't find any reference to "getProfilePhotoUrlAttribute". What makes this more confusing, is I have another project that I am porting to Laravel 10, it has JetStream installed but not used and I didn't find that function there either, and if I remove the trait no errors happen. I also did a Linux file search on both projects using grep still no reference. The only reference is in the laravel.log where the error happened.

./storage/logs/laravel.log:8752:[2023-09-04 00:40:14] local.ERROR: Call to undefined method App\Models\User::getProfilePhotoUrlAttribute() {"userId":2,"exception":"[object] (BadMethodCallException(code: 0): Call to undefined method App\Models\User::getProfilePhotoUrlAttribute() at /home/vagrant/Code/_play/pursuingsugar2.lan/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php:67)

Now I just created the function on the users model and the message went away, but it was kind of odd to be there in the first place.

And it happened on the weirdest place.

        $user_data = User::where('user_token', '=', $data['user_token'])->with('profile')->with('profile.tags')->with('tags')->first();
        dd($user_data->toArray());

on the toArray call.

Anyway, thought I would post and see if anyone had this happen to them.

Thanks

0 likes
4 replies
LaryAI's avatar
Level 58

The error message "Call to undefined method App\Models\User::getProfilePhotoUrlAttribute()" suggests that the getProfilePhotoUrlAttribute method is missing in the User model.

To resolve this issue, you need to add the HasProfilePhoto trait to your User model. Here's how you can do it:

  1. Open the User model file located at app/Models/User.php.
  2. Add the following line at the top of the file to import the HasProfilePhoto trait:
use Laravel\Jetstream\HasProfilePhoto;
  1. Add the HasProfilePhoto trait to your User model class:
class User extends Authenticatable
{
    use HasFactory, HasProfilePhoto;
    
    // Rest of your User model code...
}
  1. Save the file and try running your code again.

By adding the HasProfilePhoto trait to your User model, you will have access to the getProfilePhotoUrlAttribute method, which is responsible for retrieving the URL of the user's profile photo.

Note: If you're not using Jetstream in your project, you may need to manually define the getProfilePhotoUrlAttribute method in your User model. You can customize its behavior according to your requirements.

Let me know if you have any further questions!

1 like
TerrePorter's avatar

"Note: If you're not using Jetstream in your project, you may need to manually define the getProfilePhotoUrlAttribute method in your User model. You can customize its behavior according to your requirements."

Duh, but why should I be required to?

underdpt's avatar

Sorry if I'm late to the party. I had the same error after removing Jetstream from my app, it was due to $appends on the User model, just had to delete the profile_photo_url item:

    /**
     * The accessors to append to the model's array form.
     *
     * @var array<int, string>
     */
    protected $appends = [
        'profile_photo_url',
    ];
3 likes

Please or to participate in this conversation.