ua-parser/uap-php
UA Parser for PHP: parse browser user agents into structured data (browser, engine, OS, device) using the uap-core regex database. Helpful for analytics, logging, and device detection; easy integration via Composer and built-in caching support.
Install via Composer: composer require ua-parser/uap-php. Start by parsing a user agent string:
use UAParser\ParserFactory;
$parser = (new ParserFactory())->create();
$result = $parser->parse($userAgentString);
// Access parsed components
$userAgent = $result->userAgent;
$os = $result->os;
$device = $result->device;
Begin with common use cases: detecting mobile vs desktop (via $device->deviceName or $result->isMobile()), or browser family ($userAgent->family). Check UAParser\Result\Device, Result\OS, and Result\UserAgent classes for available properties.
Request attributes (e.g., $request->uaDevice) for consistent access throughout the request lifecycle.$result->userAgent->major, $os->family) to serve tailored UI/UX (e.g., show "mobile app" CTA only for mobile users).ParserFactory::createCached() (e.g., APCu or file-based) to avoid repeated parsing overhead in high-traffic apps.createCached() (not create()) in production—parsing is expensive without it. Defaults to FileCache (set UAPARSER_CACHE_DIR env var for control).uap-core version pinning.$result->userAgent->version may be null; always check null before formatting (e.g., sprintf('%s %s', $ua->family, $ua->version ?? 'Unknown')).$device->deviceName is often generic (e.g., “Smartphone”); use $device->model and $device->brand for specificity—but note vendor reporting inconsistencies.dd($result) to inspect the full result object structure, as many properties (e.g., $os->versionParts) are arrays requiring careful handling.UAParser\Cache\CacheInterface (e.g., Redis cache adapter) or extend Parser for custom logic.How can I help you explore Laravel packages today?