Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

nabilhassen/larasense

62 stars
2 code files
View nabilhassen/larasense on GitHub

app/Models/User.php

Open in GitHub
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Support\Uri;
 
class User extends Authenticatable implements FilamentUser, HasAvatar, MustVerifyEmail
{
// ...
 
public function avatar(): Attribute
{
return Attribute::make(
get: function (): string {
if (blank($this->avatar_url)) {
return Uri::of('https://ui-avatars.com/api/')
->withQuery([
'name' => str($this->name)->squish()->words(2, '')->replace(' ', '+')->toString(),
'background' => 'ffd0d2',
'color' => 'EF5A6F',
'rounded' => 'true',
'bold' => 'true',
])->value();
}
 
if (filled(parse_url($this->avatar_url, PHP_URL_HOST))) {
return $this->avatar_url;
}
 
return asset(str($this->avatar_url)->prepend('storage/'));
}
)->shouldCache();
}
 
// ...
}

resources/views/livewire/user-avatar.blade.php

Open in GitHub
<div x-data>
<img
loading="lazy"
src="{{ auth()->user()->avatar }}"
x-on:update-user-profile-picture.window="$wire.$refresh()"
/>
</div>

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.