Skip to content

User Avatar

Display user profile picture with optional name

The User Avatar component displays a user's profile picture with an optional name. Commonly used in Filament tables and user-related interfaces.

Preview

John DoeJohn Doe
Jane Smith

Usage

<x-shopper::user-avatar :user="$customer" />

Props

PropDefaultDescription
x-shopper::user-avatarrenders a <div> element
user
Model
required

The user model instance. Must have picture and full_name attributes.

showName
bool
true

Whether to display the user's name next to the avatar.

Examples

With Name

John DoeJohn Doe
<x-shopper::user-avatar :user="$user" />

Avatar Only

Jane Smith
<x-shopper::user-avatar :user="$user" :showName="false" />

In a Filament Table

The view needs a user variable, so render it from formatStateUsing() and pass the related user:

use Filament\Tables\Columns\TextColumn;
use Illuminate\Contracts\View\View;
use Shopper\Core\Models\Order;

TextColumn::make('customer.first_name')
    ->label(__('Customer'))
    ->formatStateUsing(fn (Order $record): View => view(
        'shopper::components.user-avatar',
        ['user' => $record->customer]
    )),

User Model Requirements

The user model must have picture and full_name attributes. The Shopper\Traits\InteractsWithShopper trait on your User model provides both: full_name joins the first and last name, and picture returns the uploaded avatar URL or a generated one.

Blade Component Source

@props([
    'user',
    'showName' => true,
])

<div class="flex items-center gap-2">
    <img class="size-8 rounded-full" src="{{ $user->picture }}" alt="{{ $user->full_name }}" />

    @if ($showName)
        <span class="text-sm font-medium text-gray-700 dark:text-gray-300">
            {{ $user->full_name }}
        </span>
    @endif
</div>

Last updated on

Edit on GitHub