F
Filament4mo ago
WEBMAS

How to show an UI Avatar on your profile?

Hello everybody. How to show an UI Avatar on your profile? I made a profile use App\Filament\Pages\Auth\EditProfile; But I don’t understand how to display my ui avatar. Just withdraw, no uploading.
15 Replies
WEBMAS
WEBMAS4mo ago
I added it to the model. What's next? How to show it now?
No description
No description
toeknee
toeknee4mo ago
Well it will show if you have added it, have you filled the avatar url for the user? So that in the show here, you mean add an edit here You need a file upload component to upload one.
WEBMAS
WEBMAS4mo ago
I don't fill in the avatar_url field in the database. This field is not there. I want to use automatic avatars https://ui-avatars.com/api/?name=a&color=FFFFFF&background=030712
toeknee
toeknee4mo ago
If you want to use automatically, then change your function to return it from there...
WEBMAS
WEBMAS4mo ago
I don't want to upload an avatar. I just want to display the avatar in the profile like in the panel on the top right.
No description
toeknee
toeknee4mo ago
$this->avatar = 'https://ui-avatars.com/api/?name=' . $this->name . '&color=FFFFFF&background=030712';
$this->avatar = 'https://ui-avatars.com/api/?name=' . $this->name . '&color=FFFFFF&background=030712';
WEBMAS
WEBMAS4mo ago
But this is not a native solution. Filament has avatar providers. Default UI Avatar. How do I use this.
toeknee
toeknee4mo ago
So you just want to render the filament avatar blade else where?
WEBMAS
WEBMAS4mo ago
I just want to display an automatic avatar. Why is it so difficult.
toeknee
toeknee4mo ago
It's not
WEBMAS
WEBMAS4mo ago
Here it comes out. How can I also display an avatar but only on the profile page?
No description
No description
LeandroFerreira
LeandroFerreira4mo ago
use Filament\Forms\Components\View;
View::make('custom-view')
use Filament\Forms\Components\View;
View::make('custom-view')
<!-- resources/views/custom-view.blade.php -->
<div>
<x-filament-panels::avatar.user :user="auth()->user()" />
</div>
<!-- resources/views/custom-view.blade.php -->
<div>
<x-filament-panels::avatar.user :user="auth()->user()" />
</div>
toeknee
toeknee4mo ago
Or with less files, assuming you have $record = UserModel.
Placeholder::make('avatar')->content(fn ($record) => new HtmlString('<img src="'.\Filament\Facades\Filament::getUserAvatarUrl($record).'"
class="h-6 w-6 flex-none rounded-full bg-gray-800" alt="Avatar" />')
),
Placeholder::make('avatar')->content(fn ($record) => new HtmlString('<img src="'.\Filament\Facades\Filament::getUserAvatarUrl($record).'"
class="h-6 w-6 flex-none rounded-full bg-gray-800" alt="Avatar" />')
),
WEBMAS
WEBMAS4mo ago
Thanks to all. Created a component /resources/views/components/userinfo.blade.php Added an avatar there. And in the profile I displayed View::make('components.userinfo'),