Files
2026-10-09 08:21:06 +02:00

36 lines
1.1 KiB
PHP

<?php
namespace App\Support;
use Closure;
use Illuminate\Support\Collection;
class SessionPayload
{
/**
* Serialise active sessions for the sessions table.
*
* The invalidate URL differs between the admin and profile views, so the
* caller supplies it rather than the template branching on a flag.
*
* @param Collection<int, object> $sessions
* @param Closure(string): string $invalidateUrl
* @return array<int, array<string, mixed>>
*/
public static function collection(Collection $sessions, Closure $invalidateUrl): array
{
return $sessions
->map(fn (object $session) => [
'id' => $session->id,
'ipAddress' => $session->ip_address,
'device' => $session->device ?: __('Unknown'),
'platform' => $session->platform ?: __('Unknown'),
'browser' => $session->browser ?: __('Unknown'),
'lastActivity' => $session->last_activity->format(config('app.date_time_format')),
'invalidateUrl' => $invalidateUrl($session->id),
])
->values()
->all();
}
}