diff --git a/app/Models/User.php b/app/Models/User.php index 8a97c1b..db99f92 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -4,6 +4,7 @@ use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Foundation\Auth\User as Authenticatable; @@ -68,6 +69,11 @@ public function activity(): HasMany return $this->hasMany(UserActivity::class); } + public function lastSeen(): Model | null + { + return $this->activity()->latest()->first(); + } + public function getAvatarAttribute(): string { return 'https://api.dicebear.com/8.x/identicon/svg?seed=' . $this->name; diff --git a/resources/views/livewire/user-show.blade.php b/resources/views/livewire/user-show.blade.php index 7da180c..5e3817c 100644 --- a/resources/views/livewire/user-show.blade.php +++ b/resources/views/livewire/user-show.blade.php @@ -60,7 +60,13 @@

Joined {{ $user->created_at->diffForHumans() }}

-

Last seen ...

+

Last seen + @if($user->lastSeen()) + {{ $user->lastSeen()->created_at->diffForHumans() }} + @else + Never + @endif +

@@ -69,7 +75,7 @@ $recent_orders = $user->orders->take(3); @endphp - @foreach ($recent_orders as $order) + @forelse ($recent_orders as $order)
@@ -85,7 +91,11 @@ class="text-blue-500">

{{ $order->description }}

- @endforeach + @empty +
+

No recent orders

+
+ @endforelse