m2collective / laravel-defining-user-device
A package for detecting the user's device.
Package info
github.com/m2collective/laravel-defining-user-device
pkg:composer/m2collective/laravel-defining-user-device
0.3.1
2026-07-27 18:20 UTC
Requires
- php: ^8.3
- laravel/framework: ^13.0
- m2collective/laravel-view-directives: ^1.0
- mobiledetect/mobiledetectlib: ^4.8
README
A package for detecting the user's device.
Installation
You can install the package via composer:
composer require m2collective/laravel-defining-user-device
Commands
Publishing the configuration file:
php artisan m2collective:defining-user-device:publish-config
The package will automatically register itself.
Usage
By installing the package, determine the user's device type.
Dependency injection
An example of using a package with the dependency injection:
use M2Collective\DefiningUserDevice\DefiningUserDevice; final class Example { /** * @var DefiningUserDevice */ protected DefiningUserDevice $definingUserDevice; /** * @param DefiningUserDevice $definingUserDevice */ public function __construct( DefiningUserDevice $definingUserDevice ) { $this->definingUserDevice = $definingUserDevice; } /** * @return mixed */ public function isDevice(): mixed { if($this->definingUserDevice->isDesktop()) { //... } else { if($this->definingUserDevice->isMobile()) { //... } else { if($this->definingUserDevice->isTablet()) { //... } else { //... } } } } }
Facades
An example of using a package with the facades:
use M2Collective\DefiningUserDevice\Facades\DefiningUserDevice; final class Example { /** * @return mixed */ public function isDevice(): mixed { if(DefiningUserDevice::isDesktop()) { //... } else { if(DefiningUserDevice::isMobile()) { //... } else { if(DefiningUserDevice::isTablet()) { //... } else { //... } } } } }
Blade Directives
An example of using a package with the blade directive:
@openingDefiningUserDesktopDevice
//...
@logicalDefiningUserDesktopDevice
//...
@closingDefiningUserDesktopDevice
or
@openingDefiningUserMobileDevice
//...
@logicalDefiningUserMobileDevice
//...
@closingDefiningUserMobileDevice
or
@openingDefiningUserTabletDevice
//...
@logicalDefiningUserTabletDevice
//...
@closingDefiningUserTabletDevice
License
The MIT License (MIT). Please see the License file for more information.