diego182/mobile-detect
Symfony bundle wrapper for Mobile Detect. Provides auto-configuration and autowiring so you can inject a MobileDetect service into your app to detect mobile/tablet devices from the user agent with minimal setup.
Mobile-Detect package is a lightweight PHP library for detecting mobile devices, tablets, and bots via user-agent strings. It fits well in architectures requiring device-aware routing, conditional UI rendering, or feature flagging (e.g., mobile-specific APIs, responsive design optimizations, or bot mitigation).App\Http\Middleware\DetectDevice). However, the Bundle wrapper (if used) may introduce unnecessary complexity for Laravel’s modular ecosystem.DependencyInjection), requiring alignment with Laravel’s DI container.HttpTestCase or standalone PHPUnit tests for user-agent parsing logic.ConfigurableBundle) necessary, or would a composer-required standalone library suffice?Request::userAgent() + regex suffice, or are advanced features (e.g., bot detection) critical?DetectDeviceMiddleware).
// app/Providers/MobileDetectServiceProvider.php
public function register() {
$this->app->singleton(MobileDetect::class, function () {
return new MobileDetect();
});
}
MobileDetect into controllers/services via constructor or resolve() methods.composer require diego182/mobile-detect.MobileDetect::create($request->userAgent()).composer require diego182/mobiledetectbundle.config/packages/mobiledetect.yaml (Symfony-style).ConfigurableInterface for dynamic rules.EventDispatcher conflicts by using standalone mode.^2.8.40).DetectDeviceMiddleware to attach detection data to requests.MobileDetect calls.Log::channel('device').| Failure | Impact | Mitigation |
|---|---|---|
| User-agent parsing error | False device classification | Fallback to regex or default to desktop |
| Library deprecation | Broken functionality | Pin version in composer.json |
| Symfony Bundle conflicts | DI container errors | Use standalone library |
| Outdated MDL4 | Missed device/bot signatures | Manually update MDL4 or fork the package |
curl, Postman, custom bots).How can I help you explore Laravel packages today?