Files
ladill-frontdesk/app/Services/Frontdesk/DeviceService.php
T
isaaccladandCursor 9e2d79936c
Deploy Ladill Frontdesk / deploy (push) Failing after 35s
Test / test (push) Failing after 2m45s
Initial Ladill Frontdesk release with deploy pipeline.
Visitor management app with SSO, kiosk, badges, reports, and Gitea CI deploy to frontdesk.ladill.com.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-27 20:37:15 +00:00

53 lines
1.3 KiB
PHP

<?php
namespace App\Services\Frontdesk;
use App\Models\Device;
use Illuminate\Support\Str;
class DeviceService
{
public function generateToken(): string
{
return Str::random(48);
}
public function findByToken(string $token): ?Device
{
return Device::query()
->where('device_token', $token)
->first();
}
public function recordHeartbeat(Device $device): Device
{
$device->update([
'status' => 'online',
'last_online_at' => now(),
]);
return $device->fresh();
}
public function markStaleDevicesOffline(int $minutes = 10): int
{
return Device::query()
->where('status', 'online')
->where(function ($q) use ($minutes) {
$q->whereNull('last_online_at')
->orWhere('last_online_at', '<', now()->subMinutes($minutes));
})
->update(['status' => 'offline']);
}
/** @param array<string, mixed> $config */
public function defaultConfigForType(string $type): array
{
return match ($type) {
'badge_printer' => ['driver' => config('frontdesk.printers.default_driver', 'pdf')],
'kiosk' => ['mode' => 'self_service', 'allow_checkout' => false],
default => [],
};
}
}