Before it's working fine , If user doesn't have image upload , show default avatar link as below
public function getAvatarPathAttribute($avatar)
{
return $avatar ? asset('storage/' . $avatar) : 'https://www.gravatar.com/avatar/';
}
After added socialite package and someone try to login with socialite (ex.github), we request user avatar and
insert to avatar_path column with full URL like that
it's work for this two condition ,
(1) if user login with Social and get their image as url
(2) If User doesn't have image upload we show default link gravatar.com
But , it doesn't work for if user upload manually via local server because return only avatar_path value like that
Check, well in that case you probably need to check if path is an URL or not and based on that perform your action.
Try this
public function getAvatarPathAttribute($avatar)
{
// Check if the value is a URL (you can also do this with a regex for a better comparison)
if (filter_var($avatar, FILTER_VALIDATE_URL)) {
return $avatar;
}
// No URL and not empty, so it's a path
if ($avatar !== null) {
return asset('storage/' . $avatar);
}
// If nothing matches, we return the default
return 'https://www.gravatar.com/avatar/';
}