This only applies to Laravel 8+.
The easiest way to replace ui-avatars.com
with gravatar is to add this method and property to your User
class.
If $profile_photo_size
is not set, it defaults to Gravatar's default which is 80 x 80px.
<?php | |
namespace App\Models; | |
use Illuminate\Support\Str; | |
class User extends Authenticatable | |
{ | |
// [...] Your other User methods/properties here | |
/** | |
* Default size in pixels for the gravatar image. | |
* | |
* Between 1 and 2048. Numbers only. | |
* | |
* Defaults to 80x80. | |
* | |
* @var string | |
*/ | |
protected $profile_photo_size = '200'; | |
/** | |
* Get the default profile photo URL if no profile photo has been uploaded. | |
* | |
* @return string | |
*/ | |
protected function defaultProfilePhotoUrl() | |
{ | |
$hashedEmail = md5(Str::lower($this->email)); | |
$sizeParameters = $this->profile_photo_size ? '?s='.$this->profile_photo_size : ''; | |
return 'https://www.gravatar.com/avatar/'.$hashedEmail.$sizeParameters; | |
} | |
} |