laravel-defining-user-device maintained by m2collective
Defining User Device
A package for detecting the user's device.
Installation
You can install the package via composer:
composer require m2collective/laravel-defining-user-device
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.