提问人:Rafael Munoz 提问时间:2/27/2020 更新时间:2/27/2020 访问量:536
Gravatar 错误:请指定有效的电子邮件地址
Gravatar Error: Please specify a valid email address
问:
我正在尝试在我的应用程序中使用 gravatar。
我有一群员工。并非所有人都有照片,因此我检查avatar_type === gravatar是否存在,以便传递电子邮件的有效URL,因此我做了一个循环:
foreach ($employees as $employee) {
if($employee->avatar_type === 'gravatar') {
$employee->avatar_location = gravatar()->get($employee->email, ['size'=>80]);
}
}
该系列的第一件物品没有照片,需要重力,如下所示:
App\Models\Employee\Employee {#2898 ▼
...
#attributes: array:14 [▼
"firstname" => "Mary"
"lastname" => "Brown"
"email" => "[email protected]"
"avatar_location" => null
"avatar_type" => "gravatar" // <- Here is the flag
]
但是,即使电子邮件有效(“电子邮件”=>“[email protected]”),我也会收到以下错误:
Creativeorange\Gravatar\Exceptions\InvalidEmailException
请指定有效的电子邮件地址
我什至做了一个测试,并在循环中“dd”电子邮件,电子邮件就在那里。喜欢这个:
foreach ($employees as $employee) {
dd($employee->email) //<- The email is here
if($employee->avatar_type === 'gravatar') {
$employee->avatar_location = gravatar()->get($employee->email, ['size'=>80]);
}
}
我在这里错过了什么。为什么电子邮件无效?
我正在使用 Laravel 6.13
gravatar 包在应用程序的其他位置(在用户配置文件页面中)下载、安装并运行。
答:
0赞
KPK
2/27/2020
#1
在继续操作之前,您需要清理所有输入。在laravel中,我们可以编写一个简单的中间件来执行此任务。这是一篇解释清楚的文章。查看此 Medium 文章希望这会有所帮助。
评论
dd($employee->email)
这将在第一个员工/迭代时停止。可能是其他用户的电子邮件ID无效