userAgent(); } public static function findUA(?string $ua = null): ?int { $ua ??= app('browser-detect')->userAgent(); $row = DB::table('user_agents')->where('user_agent', $ua)->first(['id']); if ($row) { return $row->id; } return null; } public static function upsertBrowser(?string $ua = null): int { $browser = blank($ua) ? app('browser-detect')->detect() : app('browser-detect')->parse($ua); $id = self::findUA($browser->userAgent()); if ($id) { return $id; } $params = [ 'user_agent' => $browser->userAgent(), 'device_type' => $browser->deviceType(), 'device_family' => $browser->deviceFamily(), 'device_model' => $browser->deviceModel(), 'browser_name' => $browser->browserName(), 'browser_version' => $browser->browserVersion(), 'platform' => $browser->platformFamily(), 'platform_version' => $browser->platformVersion(), 'created_at' => now(), ]; DB::table('user_agents')->insert($params); return self::findUA($browser->userAgent()); } }