douwo8358
douwo8358
2015-09-25 09:22

Laravel 5 - MD5 Hash错误gravatar

已采纳

I'm trying to use Gravatar which requires an MD5 hash on the email, when I try this using Laravel and blade it just outputs my code instead of running it.

Model

public function getAvatarUrl()
{
    return "https://www.gravatar.com/avatar/{{ md5($this->email) }}?d=mm&s=40";
}

View

<img class="media-object avatar" alt="{{ $status->user->getNameOrUsername() }}" src="{{ $status->user->getAvatarUrl() }}">

The out put on the page is such -

<img class="media-object avatar" alt="Sam" src="https://www.gravatar.com/avatar/{{ md5(sam@myemail.co.uk) }}?d=mm&amp;s=50">
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • duanpuqi9965 duanpuqi9965 6年前

    You can't use blade syntax like {{ }} in a return. Blade syntax is only allowed in blade templates.

    Try this in your model:

    public function getAvatarUrl()
    {
        return "https://www.gravatar.com/avatar/" . md5($this->email) . "?d=mm&s=40";
    }
    
    点赞 评论 复制链接分享

相关推荐