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
Mobiledetectlib

Mobiledetectlib Laravel Package

mobiledetect/mobiledetectlib

Lightweight PHP class to detect mobile phones and tablets using User-Agent plus HTTP headers. Identify device type and specific platforms/brands for responsive content, analytics, or redirects. Widely used and actively maintained via tagged major branches.

View on GitHub
Deep Wiki
Context7

Mobile_Detect is a lightweight PHP class for detecting mobile devices. It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.

Frequently asked questions about Mobiledetectlib
How do I install Mobile_Detect in a Laravel project?
Run `composer require mobiledetect/mobiledetectlib` to install the latest version. For Laravel 10+, use `^4.10` for PHP 8.2+ compatibility. The package has no Laravel-specific dependencies, so it integrates cleanly into any project.
Can I use this package with Laravel’s caching system?
Yes. Mobile_Detect is PSR-16 compliant since version 4.10.0, so you can cache detection results using Laravel’s cache drivers (Redis, Memcached, etc.). Use `Cache::remember()` to avoid repeated User-Agent parsing in high-traffic apps.
Does this work with Laravel middleware for mobile-specific routes?
Absolutely. Create a `MobileDetectMiddleware` that instantiates `Mobile_Detect` from the request’s User-Agent, then route mobile/tablet users to dedicated endpoints (e.g., `/api/mobile`). Example: `if ($detect->isMobile()) return redirect()->to('/mobile');`
What Laravel versions does mobiledetect/mobiledetectlib support?
The 4.x branch (latest) requires PHP 8.2+ and works seamlessly with Laravel 10+. For older Laravel (e.g., 8/9), use the 3.x branch (PHP 7.4+). Check the [README](https://github.com/serbanghita/Mobile-Detect) for branch-specific details.
How accurate is device detection for tablets vs. phones?
Mobile_Detect uses a combination of User-Agent strings and HTTP headers for high accuracy. Methods like `isTablet()` and `isMobile()` are reliable for most devices, but edge cases (e.g., foldable phones) may require custom regex patterns or testing.
Can I extend Mobile_Detect to support custom device detection?
Yes. The library allows custom regex patterns via `addUserAgent()` or subclassing `Mobile_Detect`. For example, override detection logic for enterprise tablets or niche devices by extending the class and injecting it into Laravel’s service container.
Will this package slow down my Laravel application?
No. Mobile_Detect is lightweight (~10KB) and has negligible overhead. For high-traffic APIs, cache detection results (e.g., 5-minute TTL) to avoid repeated parsing. Benchmark with `Mobile_Detect::create($request->userAgent())` vs. cached results.
Does this work behind proxies like Cloudflare or Nginx?
Yes. Mobile_Detect auto-detects proxy headers (e.g., `CF-User-Agent`) or manually pass headers via `setHttpHeaders()`. For Laravel, use `$request->header()` to fetch proxy-specific User-Agent strings before detection.
Are there alternatives to Mobile_Detect for Laravel?
Yes. Alternatives include `laravel-user-agent` (Laravel-specific but heavier) or `jenssegers/agent` (feature-rich but less lightweight). Mobile_Detect stands out for its minimalism, PSR-16 cache support, and vendor-agnostic design.
How do I test Mobile_Detect in Laravel’s unit tests?
Mock the `$_SERVER['HTTP_USER_AGENT']` or Laravel’s `Request` object in tests. Example: `$request = Request::create('/', [], [], [], [], ['HTTP_USER_AGENT' => 'iPhone User-Agent']); $detect = Mobile_Detect::create($request->userAgent()); $this->assertTrue($detect->isMobile());`
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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai