where('device_token', $token) ->first(); } public function recordHeartbeat(Device $device): void { $device->update([ 'status' => 'online', 'last_online_at' => now(), ]); } public function markStaleOffline(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']); } public function generateToken(Device $device): string { $token = Str::random(48); $device->update(['device_token' => $token]); return $token; } }