Skip to content

Commit 117aa33

Browse files
author
Zacchaeus Bolaji
committed
Added mobile detection
1 parent 2a975d8 commit 117aa33

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,25 @@ The language method allows you to detect a user's language.
175175
Identify::lang()->getLanguage()
176176
```
177177

178+
## Mobile Detection
179+
180+
The mobile method allows you to detect if user is on mobile.
181+
182+
### Usage
183+
184+
```php
185+
/**
186+
* Returns true if any type of mobile device detected, including special ones
187+
* @return boolean
188+
*/
189+
Identify::mobile()->isMobile()
190+
191+
/**
192+
* Return true if any type of tablet device is detected.
193+
* @return boolean
194+
*/
195+
Identify::mobile()->isTablet()
196+
```
178197

179198
## Contributing
180199

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
"require": {
1313
"php": ">=7.1.3",
1414
"illuminate/support": "~5.7.0|~5.8.0",
15-
"sinergi/browser-detector": "6.1.*"
15+
"sinergi/browser-detector": "6.1.*",
16+
"mobiledetect/mobiledetectlib": "^2.8"
1617
},
17-
"require-dev": {
18+
"require-dev": {
1819
"phpunit/phpunit": "~6.0.0",
1920
"mockery/mockery": "0.9.*",
2021
"scrutinizer/ocular": "~1.1",

src/Identify.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ class Identify {
3030
*/
3131
protected $language;
3232

33+
/**
34+
* Store the mobile object
35+
* @var object
36+
*/
37+
protected $mobile;
38+
3339
/**
3440
* Create an Instance of Browser and Os
3541
*/
@@ -39,6 +45,7 @@ public function __construct()
3945
$this->device = new Device();
4046
$this->browser = new Browser();
4147
$this->language = new Language();
48+
$this->mobile = new \Mobile_Detect();
4249
}
4350

4451
/**
@@ -81,4 +88,14 @@ public function lang() : Language
8188
return $this->language;
8289
}
8390

84-
}
91+
/**
92+
* Get all the methods applicable to Mobile detection
93+
* e.g isMobile()
94+
* @return \Mobile_Detect
95+
*/
96+
public function mobile() : \Mobile_Detect
97+
{
98+
return $this->mobile;
99+
}
100+
101+
}

tests/IdentifyTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,13 @@ public function testLanguageIsInitializedOnIdentifyConstruction()
6565
{
6666
$this->assertInstanceOf(Language::class, $this->identify->lang());
6767
}
68+
69+
/**
70+
* Test if Mobile returns bool
71+
*
72+
*/
73+
public function testMobileIsInitializedOnIdentifyConstruction()
74+
{
75+
$this->assertInstanceOf(\Mobile_Detect::class, $this->identify->mobile());
76+
}
6877
}

0 commit comments

Comments
 (0)