Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Device Detector

Device Detector Laravel Package

piwik/device-detector

Parse User-Agent strings and Browser Client Hints to identify device type (desktop/tablet/mobile/TV/console, etc.), browser/client, operating system, and device brand/model. Universal PHP library from Matomo for accurate device detection.

View on GitHub
Deep Wiki
Context7

The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.

Frequently asked questions about Device Detector
How do I install and use this package in Laravel?
Run `composer require matomo/device-detector`, then instantiate the detector with `new DeviceDetector($userAgent, $clientHints)`. For Laravel, inject `Request` to access `HTTP_USER_AGENT` and optionally `Accept-CH` headers. Wrap logic in a service or middleware for reuse.
Does this work with Laravel’s caching system?
Yes. The package supports PSR-6/PSR-16 caches (e.g., Redis, APCu) via Laravel’s cache drivers. Configure it with `new CacheAdapter($cacheDriver)` for persistent storage. Defaults to in-memory caching for single requests.
What Laravel versions does this package support?
The package works with **PHP 8.1+** and **Laravel 9+** (tested with Symfony components). Check `composer.json` for exact constraints. No known conflicts with Laravel’s ecosystem, but test thoroughly in your stack.
Can I use this for bot detection in Laravel?
Absolutely. The library identifies bots/spiders (e.g., Googlebot, Scrapy) via User-Agent parsing. Combine with IP-based bot lists (e.g., Spamhaus) for higher accuracy. Use middleware to block or log suspicious agents globally.
How accurate is device detection compared to alternatives?
This library achieves **~95%+ accuracy** for modern devices (tested against UAParser benchmarks). For edge cases, audit false positives/negatives with real user agents. Fallback to regex if needed, but caching improves performance.
Should I cache results in production?
Yes. Use **Redis or APCu** for high-traffic apps (e.g., 10K+ RPS) with a short TTL (e.g., 1 hour). Cache warming or invalidation may be needed for dynamic user agents. Avoid filesystem caching in shared environments.
How do I integrate this with Laravel middleware?
Create a middleware (e.g., `DeviceDetectorMiddleware`) that parses `HTTP_USER_AGENT` on every request. Store results in the request object or session. Example: `public function handle(Request $request, Closure $next) { $detector = new DeviceDetector($request->userAgent()); $request->merge(['device' => $detector->getDevice()]); return $next($request); }`
Are there performance concerns for high-traffic Laravel apps?
The package is lightweight (~10ms per request without caching). For high throughput, enable **Redis caching** and skip bot detection on non-critical paths. Benchmark with your traffic load to optimize TTL or cache strategies.
Can I customize device/OS/browser rules?
Yes. The library uses YAML-based rules (extendable via `DeviceDetector::setRules()`). Fork the [rules repository](https://github.com/piwik/device-detector/tree/master/rules) to add custom devices or override defaults. Test changes with real user agents.
Does this comply with GDPR/CCPA for storing device data?
The package itself doesn’t store data—it parses User-Agent strings. If you log device info, ensure compliance via **consent management systems** (e.g., Laravel’s `laravel-analytics`). Anonymize or encrypt sensitive data before storage.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views