diff --git a/README.md b/README.md index c21caff..6a2c003 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,25 @@ The language method allows you to detect a user's language. Identify::lang()->getLanguage() ``` +## Mobile Detection + +The mobile method allows you to detect if user is on mobile. + +### Usage + +```php +/** + * Returns true if any type of mobile device detected, including special ones + * @return boolean + */ +Identify::mobile()->isMobile() + +/** + * Return true if any type of tablet device is detected. + * @return boolean + */ +Identify::mobile()->isTablet() +``` ## Contributing diff --git a/composer.json b/composer.json index 4b10046..ec0ec50 100644 --- a/composer.json +++ b/composer.json @@ -12,9 +12,10 @@ "require": { "php": ">=7.1.3", "illuminate/support": "~5.7.0|~5.8.0", - "sinergi/browser-detector": "6.1.*" + "sinergi/browser-detector": "6.1.*", + "mobiledetect/mobiledetectlib": "^2.8" }, - "require-dev": { + "require-dev": { "phpunit/phpunit": "~6.0.0", "mockery/mockery": "0.9.*", "scrutinizer/ocular": "~1.1", diff --git a/src/Identify.php b/src/Identify.php index 4b47f19..63fb908 100644 --- a/src/Identify.php +++ b/src/Identify.php @@ -30,6 +30,12 @@ class Identify { */ protected $language; + /** + * Store the mobile object + * @var object + */ + protected $mobile; + /** * Create an Instance of Browser and Os */ @@ -39,6 +45,7 @@ public function __construct() $this->device = new Device(); $this->browser = new Browser(); $this->language = new Language(); + $this->mobile = new \Mobile_Detect(); } /** @@ -81,4 +88,14 @@ public function lang() : Language return $this->language; } -} \ No newline at end of file + /** + * Get all the methods applicable to Mobile detection + * e.g isMobile() + * @return \Mobile_Detect + */ + public function mobile() : \Mobile_Detect + { + return $this->mobile; + } + +} diff --git a/tests/IdentifyTest.php b/tests/IdentifyTest.php index 805a058..98d5fc9 100644 --- a/tests/IdentifyTest.php +++ b/tests/IdentifyTest.php @@ -65,4 +65,13 @@ public function testLanguageIsInitializedOnIdentifyConstruction() { $this->assertInstanceOf(Language::class, $this->identify->lang()); } + + /** + * Test if MobileDetect is constructed on Identify Object created + * + */ + public function testMobileIsInitializedOnIdentifyConstruction() + { + $this->assertInstanceOf(\Mobile_Detect::class, $this->identify->mobile()); + } }