{{-- Shared user-avatar block — used by both admin and front layouts. Renders the user's uploaded `users.image` if it's set; otherwise an initials badge (first letter of each word in the name, max 2 chars). "Rahul Agrawal" → "RA". Inputs: $user (App\Models\User|null) defaults to auth()->user() $size (int|null) pixel size of the avatar (default 40) $classes (string|null) extra CSS classes for the outer element Static styling (.avatar-letter / .avatar-image) lives in both public/theme/admin/css/admin.css and public/theme/front/assets/css/main.css. Used by: admin/partials/sidebar.blade.php admin/partials/topbar.blade.php layouts/front/partials/header.blade.php --}} @php $user = $user ?? auth()->user(); $size = $size ?? 40; $classes = $classes ?? ''; $displayName = trim((string) ($user->name ?? ($user->first_name ?? 'User'))); // Build initials: first letter of up to 2 whitespace-separated words. $initials = collect(preg_split('/\s+/u', $displayName, -1, PREG_SPLIT_NO_EMPTY)) ->take(2) ->map(fn ($w) => mb_strtoupper(mb_substr($w, 0, 1))) ->implode(''); if ($initials === '') $initials = 'U'; $hasImage = !empty($user->image ?? null); @endphp @if ($hasImage) {{ $displayName }} @else {{-- font-size = size * 0.5 keeps the initials comfortably readable at small badge sizes (front header uses size=28 → 14px font, was 11px with the previous 0.4 multiplier). --}}
{{ $initials }}
@endif