diff --git a/app/Models/User.php b/app/Models/User.php index ef69705..9e77400 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,6 +2,7 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Appends; use Illuminate\Database\Eloquent\Attributes\Guarded; use Illuminate\Database\Eloquent\Attributes\Scope; use Illuminate\Database\Eloquent\Builder; @@ -16,6 +17,7 @@ use Spatie\Permission\Traits\HasRoles; #[Guarded(['id'])] +#[Appends(['full_name'])] class User extends Authenticatable { use HasFactory, HasRoles, Notifiable, SoftDeletes, TwoFactorAuthenticatable; @@ -37,10 +39,17 @@ protected function active(Builder $query): void $query->where('is_active', true); } + protected function name(): Attribute + { + return Attribute::make( + get: fn() => $this->userProfile?->full_name ?? '', + ); + } + protected function fullName(): Attribute { return Attribute::make( - get: fn () => $this->userProfile?->full_name ?? '', + get: fn() => $this->userProfile?->full_name ?? '', ); } diff --git a/resources/js/components/user-info.tsx b/resources/js/components/user-info.tsx index dd0848e..6284d7a 100644 --- a/resources/js/components/user-info.tsx +++ b/resources/js/components/user-info.tsx @@ -14,13 +14,13 @@ export function UserInfo({ return ( <> - + - {getInitials(user.name)} + {getInitials(user.full_name)}
- {user.name} + {user.full_name} {showEmail && ( {user.email} diff --git a/resources/js/types/auth.ts b/resources/js/types/auth.ts index bfda3af..fb2fe3c 100644 --- a/resources/js/types/auth.ts +++ b/resources/js/types/auth.ts @@ -1,6 +1,7 @@ export type User = { id: number; name: string; + full_name: string; email: string; avatar?: string; email_verified_at: string | null; @@ -18,6 +19,7 @@ export type Auth = { export type Passkey = { id: number; name: string; + full_name: string; authenticator: string | null; created_at_diff: string; last_used_at_diff: string | null;