Skip to content

Commit a293584

Browse files
committed
chore: change device detector
1 parent de00c6f commit a293584

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

app/Helpers/Utils.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\Helpers;
4+
5+
use DeviceDetector\DeviceDetector;
6+
7+
class Utils
8+
{
9+
public static function getDeviceDetectorByUserAgent(string $userAgent): DeviceDetector
10+
{
11+
$detector = new DeviceDetector(
12+
userAgent: $userAgent,
13+
);
14+
15+
$detector->parse();
16+
17+
return $detector;
18+
}
19+
20+
/**
21+
* Get device name from user agent
22+
*/
23+
public static function getDeviceNameFromDetector(DeviceDetector $device): string
24+
{
25+
return implode(' / ', array_filter([
26+
trim(implode(' ', [$device->getOs('name'), $device->getOs('version')])),
27+
trim(implode(' ', [$device->getClient('name'), $device->getClient('version')])),
28+
])) ?? 'Unknown';
29+
}
30+
}

app/Providers/AppServiceProvider.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,12 @@ public function boot(): void
102102
return Str::replaceMatches('/[^\p{L}\d ]/u', '', $text);
103103
});
104104

105-
Request::macro('deviceName', function (): string {
106-
$device = $this->device();
105+
Request::macro('device', function () {
106+
return Utils::getDeviceDetectorByUserAgent($this->userAgent());
107+
});
107108

108-
return implode(' / ', array_filter([
109-
trim(implode(' ', [$device->getOs('name'), $device->getOs('version')])),
110-
trim(implode(' ', [$device->getClient('name'), $device->getClient('version')])),
111-
])) ?? 'Unknown';
109+
Request::macro('deviceName', function (): string {
110+
return Utils::getDeviceNameFromDetector($this->device());
112111
});
113112

114113
Sanctum::usePersonalAccessTokenModel(

composer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
"name": "laravel/laravel",
44
"type": "project",
55
"description": "The skeleton application for the Laravel framework.",
6-
"keywords": ["laravel", "framework"],
6+
"keywords": [
7+
"laravel",
8+
"framework"
9+
],
710
"license": "MIT",
811
"require": {
912
"php": "^8.3",
@@ -14,7 +17,7 @@
1417
"laravel/socialite": "^5.12",
1518
"laravel/tinker": "^2.9",
1619
"league/flysystem-aws-s3-v3": "^3.24",
17-
"reefki/laravel-device-detector": "^1.0",
20+
"matomo/device-detector": "^6.4",
1821
"spatie/laravel-permission": "^6.4",
1922
"symfony/filesystem": "^7.2"
2023
},
@@ -79,4 +82,4 @@
7982
},
8083
"minimum-stability": "stable",
8184
"prefer-stable": true
82-
}
85+
}

0 commit comments

Comments
 (0)