Search code examples
phplaravelgravatar

Gravatar inside Laravel


I have managed to produce the string output of the gravatar image associated with the email address but struggling to actually show the image...

This is inside of User.php within the Model file.

public function getGravatarAttribute()
    {
        $hash = md5(strtolower(trim($this->attributes['email'])));
        return "http://www.gravatar.com/avatar/$hash";
    }

Showing the output using this:

<li>{{ Auth::user()->gravatar }}</li>

I need to now turn this into the actual Gravatar image...but a tad stuck


Solution

  • Just use the URL as src for an image element:

    <img src="{{ Auth::user()->gravatar }}"/>