@squarenetmedia You can check if the user has uploaded an avatar by checking if the user has any media items associated with the "avatars" collection. Here's an example of how you can check if the user has an avatar and return the appropriate URL:
public function getAvatarAttribute()
{
if ($this->hasMedia('avatars')) {
$avatar = $this->getFirstMedia('avatars')->getUrl();
} else {
$avatar = asset('/img/placeholders/default.png');
}
return $avatar;
}
This code uses the hasMedia() method to check if the user has any media items associated with the "avatars" collection. If they do, it uses the getFirstMedia() method to get the first media item associated with that collection and then getUrl() method to get the URL of that media item. If the user does not have any media items associated with the "avatars" collection, it will return the URL of the default image.