PHPackages                             sajidwarner/laravel-device-detector - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sajidwarner/laravel-device-detector

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sajidwarner/laravel-device-detector
===================================

LaraTrack — Laravel package for browser detection, device detection, IP geolocation, bot detection, Tor detection and platform detection

v1.4.0(2mo ago)5132MITPHPPHP ^8.1

Since Oct 30Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/sajidwarner/laratrack)[ Packagist](https://packagist.org/packages/sajidwarner/laravel-device-detector)[ RSS](/packages/sajidwarner-laravel-device-detector/feed)WikiDiscussions main Synced today

READMEChangelog (5)Dependencies (12)Versions (13)Used By (0)

LaraTrack
=========

[](#laratrack)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e9f699565ff1ef8da8198d9df8e0d6d36c580321f6a207d574f6972e10a02180/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73616a69647761726e65722f6c61726176656c2d6465766963652d6465746563746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sajidwarner/laravel-device-detector)[![Total Downloads](https://camo.githubusercontent.com/103c8eec443887154ac8c4b3ded6d56d06149e378a5e630985e2d8c106a618fe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73616a69647761726e65722f6c61726176656c2d6465766963652d6465746563746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sajidwarner/laravel-device-detector)[![PHP Version](https://camo.githubusercontent.com/a47356fd45cc42418526f84080dc9af2ef66b1e6f2317039ff443833a25be9a9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f73616a69647761726e65722f6c61726176656c2d6465766963652d6465746563746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sajidwarner/laravel-device-detector)[![License](https://camo.githubusercontent.com/f7da3460b7898d6ceed08e5cb8afce3e8d1168e8516897c195d82ea71aae12a8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f73616a69647761726e65722f6c61726176656c2d6465766963652d6465746563746f722e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Tests](https://camo.githubusercontent.com/15c0146a122b9e583f46f18f20ecec017271127cd414c380b7c13d207694bf4c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d333625323070617373696e672d627269676874677265656e3f7374796c653d666c61742d737175617265)](#testing)

A powerful Laravel package for **browser detection**, **device detection**, **IP geolocation**, **VPN/Proxy detection**, **bot/robot detection**, **Tor detection**, **language detection**, and **platform detection** — with built-in middleware, Laravel events, and Artisan commands. Supports Laravel 10, 11, 12, and 13 with PHP 8.1+.

Features
--------

[](#features)

- 🌐 **Browser Detection** — Chrome, Firefox, Safari, Edge, Opera, Brave, Vivaldi, Tor Browser, Kahf, DuckDuckGo, Samsung Internet, UC Browser, and more
- 📱 **Mobile Device Detection** — Detect brand and model (Apple, Samsung, Xiaomi, Huawei, OnePlus, Oppo, Vivo, Google Pixel, Motorola, Nokia, LG, Sony, HTC)
- 💻 **Desktop Detection** — Identify desktop browsers and operating systems
- 📊 **Tablet Detection** — iPad, Android tablets, Kindle, and more
- 🤖 **Robot / Bot Detection** — 26+ bots: Googlebot, Bingbot, Facebook, Twitter, LinkedIn, WhatsApp, Telegram, Semrush, Ahrefs, and more
- 🔒 **Tor Detection** — Real-time Tor exit node detection with caching
- 🛡️ **VPN &amp; Proxy Detection** — Detect VPN and proxy connections via geolocation security data
- 🗺️ **IP Geolocation** — Country, city, timezone, ISP, currency via [ipgeolocation.io](https://app.ipgeolocation.io/signup?referral=AFF-YWEVCOJFNY) (free plan available)
- 🌍 **Language Detection** — Detect visitor's preferred language from `Accept-Language` header
- 🖥️ **Platform / OS Detection** — Windows 10, macOS, Linux, Android, iOS, Chrome OS, and more
- 🚧 **Built-in Middleware** — Block bots, Tor, VPN, specific countries, or restrict to mobile/desktop
- ⚡ **Laravel Events** — Fire events on bot, Tor, or VPN detection
- 🖥️ **Artisan Commands** — `laratrack:test`, `laratrack:clear-cache`
- 🎯 **Client Hints Support** — Uses modern `Sec-CH-UA` headers as primary detection method
- 🔧 **Blade Directives** — `@mobile`, `@tablet`, `@desktop`, `@robot`, `@tor`, `@vpn`, `@proxy`
- ⚡ **Performance** — Per-IP caching for geolocation and Tor nodes

Installation
------------

[](#installation)

```
composer require sajidwarner/laravel-device-detector
```

Laravel's auto-discovery will automatically register the service provider and facade.

### Manual Registration (Optional)

[](#manual-registration-optional)

If auto-discovery is disabled, add to `config/app.php`:

```
'providers' => [
    SajidWarner\LaraTrack\LaraTrackServiceProvider::class,
],

'aliases' => [
    'LaraTrack' => SajidWarner\LaraTrack\Facades\LaraTrack::class,
],
```

### Publish Configuration

[](#publish-configuration)

```
php artisan vendor:publish --provider="SajidWarner\LaraTrack\LaraTrackServiceProvider"
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use SajidWarner\LaraTrack\Facades\LaraTrack;

$browser   = LaraTrack::getBrowser();     // "Google Chrome"
$platform  = LaraTrack::getPlatform();    // "Windows 10"
$type      = LaraTrack::getDeviceType();  // "desktop" | "mobile" | "tablet"
$language  = LaraTrack::getLanguage();    // "en-US", "bn-BD" ...
$isMobile  = LaraTrack::isMobile();       // true / false
$isTablet  = LaraTrack::isTablet();       // true / false
$isDesktop = LaraTrack::isDesktop();      // true / false
$isRobot   = LaraTrack::isRobot();        // true / false
$isTor     = LaraTrack::isTor();          // true / false
$isVpn     = LaraTrack::isVpn();          // true / false
$isProxy   = LaraTrack::isProxy();        // true / false
$location  = LaraTrack::getLocation();    // array (when geolocation enabled)
```

### Full Detection Array

[](#full-detection-array)

```
$data = LaraTrack::detect();

/*
[
    'browser'         => 'Google Chrome',
    'browser_version' => '120.0',
    'platform'        => 'Windows 10',
    'device_type'     => 'desktop',
    'device_brand'    => null,
    'device_model'    => null,
    'is_mobile'       => false,
    'is_tablet'       => false,
    'is_desktop'      => true,
    'is_robot'        => false,
    'is_tor'          => false,
    'is_vpn'          => false,
    'is_proxy'        => false,
    'robot_name'      => null,
    'language'        => 'en-US',
    'ip'              => '192.168.1.1',
    'location'        => [                  // only when geolocation is enabled
        'country'       => 'Bangladesh',
        'country_code'  => 'BD',
        'city'          => 'Dhaka',
        'state'         => 'Dhaka Division',
        'district'      => 'Dhaka',
        'zip'           => '1000',
        'latitude'      => '23.72305',
        'longitude'     => '90.40860',
        'timezone'      => 'Asia/Dhaka',
        'isp'           => 'Ranks ITT',
        'organization'  => 'AS24323 Ranks ITT',
        'currency'      => 'BDT',
        'calling_code'  => '+880',
        'is_eu'         => false,
    ],
]
*/
```

### In Controllers

[](#in-controllers)

```
use Illuminate\Http\Request;
use SajidWarner\LaraTrack\Facades\LaraTrack;

class HomeController extends Controller
{
    public function index(Request $request)
    {
        $device = LaraTrack::detect($request);

        if ($device['is_mobile']) {
            return view('mobile.home', compact('device'));
        }

        if ($device['is_robot']) {
            return response('Bot detected: ' . $device['robot_name']);
        }

        return view('home', compact('device'));
    }
}
```

Middleware
----------

[](#middleware)

LaraTrack registers 6 middleware aliases automatically — no manual registration needed.

### Available Middleware

[](#available-middleware)

```
// Block all bots/crawlers
Route::middleware('laratrack.block-bots')->group(function () {
    Route::get('/members', MembersController::class);
});

// Block Tor connections
Route::middleware('laratrack.block-tor')->group(function () {
    Route::post('/checkout', CheckoutController::class);
});

// Block VPN and Proxy connections
Route::middleware('laratrack.block-vpn')->group(function () {
    Route::post('/login', LoginController::class);
});

// Allow mobile devices only
Route::middleware('laratrack.mobile-only')->group(function () {
    Route::get('/app', AppController::class);
});

// Allow desktop only
Route::middleware('laratrack.desktop-only')->group(function () {
    Route::get('/dashboard', DashboardController::class);
});

// Block specific countries (inline)
Route::middleware('laratrack.block-countries:CN,RU,KP')->group(function () {
    Route::get('/api', ApiController::class);
});
```

### Country Blocking via Config

[](#country-blocking-via-config)

Block countries globally in `config/laratrack.php`:

```
'blocked_countries' => ['CN', 'RU', 'KP'],
```

Then just apply the middleware without parameters:

```
Route::middleware('laratrack.block-countries')->group(...);
```

### Custom Middleware Messages / Redirects

[](#custom-middleware-messages--redirects)

```
// config/laratrack.php
'middleware' => [
    'bot_message'          => 'Bots are not allowed.',
    'tor_message'          => 'Tor connections are not allowed.',
    'vpn_message'          => 'VPN/Proxy connections are not allowed.',
    'country_message'      => 'Your country is not allowed.',
    'mobile_only_message'  => 'Please use a mobile device.',
    'desktop_only_message' => 'Please use a desktop browser.',
    'mobile_redirect'      => '/download-app', // redirect desktop users
    'desktop_redirect'     => '/desktop-only', // redirect mobile users
],
```

Events
------

[](#events)

LaraTrack fires Laravel events automatically when threats are detected. Listen to them in your `EventServiceProvider` or using `#[AsEventListener]`.

```
// app/Providers/EventServiceProvider.php
protected $listen = [
    \SajidWarner\LaraTrack\Events\BotDetected::class  => [App\Listeners\HandleBot::class],
    \SajidWarner\LaraTrack\Events\TorDetected::class  => [App\Listeners\HandleTor::class],
    \SajidWarner\LaraTrack\Events\VpnDetected::class  => [App\Listeners\HandleVpn::class],
];
```

### Event Payloads

[](#event-payloads)

```
// BotDetected
$event->request;  // Illuminate\Http\Request
$event->botName;  // "Googlebot"
$event->ip;       // "66.249.66.1"

// TorDetected
$event->request;
$event->ip;

// VpnDetected
$event->request;
$event->ip;
$event->type;     // "vpn" or "proxy"
```

### Example Listener

[](#example-listener)

```
namespace App\Listeners;

use SajidWarner\LaraTrack\Events\BotDetected;
use Illuminate\Support\Facades\Log;

class HandleBot
{
    public function handle(BotDetected $event): void
    {
        Log::warning("Bot detected: {$event->botName} from IP {$event->ip}");
    }
}
```

Disable events in config if not needed:

```
'fire_events' => false,
```

Artisan Commands
----------------

[](#artisan-commands)

### Test Detection

[](#test-detection)

Test LaraTrack detection from the terminal with any User-Agent string:

```
# Default Chrome UA
php artisan laratrack:test

# Custom User-Agent
php artisan laratrack:test "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15"

# With IP (for geolocation)
php artisan laratrack:test "Mozilla/5.0 Chrome/120.0.0.0" --ip=8.8.8.8
```

Example output:

```
LaraTrack Detection Result
─────────────────────────────────
+──────────────+──────────────────────+
| Field        | Value                |
+──────────────+──────────────────────+
| Browser      | Google Chrome 120.0  |
| Platform     | Windows 10           |
| Device Type  | desktop              |
| Is Mobile    | No                   |
| Is Robot     | No                   |
| Is Tor       | No                   |
| Is VPN       | No                   |
| Language     | en-US                |
| IP           | 8.8.8.8              |
+──────────────+──────────────────────+

```

### Clear Cache

[](#clear-cache)

```
php artisan laratrack:clear-cache
```

Clears cached Tor exit nodes and all geolocation results.

Blade Directives
----------------

[](#blade-directives)

```
@mobile
    Shown only on mobile
@endmobile

@tablet
    Shown only on tablets
@endtablet

@desktop
    Shown only on desktop
@enddesktop

@robot
    Bot/crawler detected
@endrobot

@tor
    Tor browser detected
@endtor

@vpn
    VPN connection detected
@endvpn

@proxy
    Proxy connection detected
@endproxy
```

IP Geolocation
--------------

[](#ip-geolocation)

Get real-time location data for any visitor IP using [ipgeolocation.io](https://app.ipgeolocation.io/signup?referral=AFF-YWEVCOJFNY).

**Free plan:** 30,000 requests/month — no credit card required.

> 🔗 **Sign up here (free):**

### Setup

[](#setup)

1. Sign up at [ipgeolocation.io](https://app.ipgeolocation.io/signup?referral=AFF-YWEVCOJFNY) and get your free API key
2. Add to your `.env` file (**never commit your API key to git**):

```
LARATRACK_GEO_ENABLED=true
LARATRACK_GEO_API_KEY=your_own_api_key_here
```

3. Use in your application:

```
$location = LaraTrack::getLocation();

echo $location['country'];      // Bangladesh
echo $location['city'];         // Dhaka
echo $location['timezone'];     // Asia/Dhaka
echo $location['isp'];          // Ranks ITT
echo $location['currency'];     // BDT
echo $location['calling_code']; // +880
```

### Geolocation Response Fields

[](#geolocation-response-fields)

FieldDescriptionExample`country`Full country name`Bangladesh``country_code`ISO 2-letter code`BD``city`City name`Dhaka``state`State / Province`Dhaka Division``district`District`Dhaka``zip`Postal / ZIP code`1000``latitude`Latitude`23.72305``longitude`Longitude`90.40860``timezone`Timezone name`Asia/Dhaka``isp`Internet Service Provider`Ranks ITT``organization`AS organization`AS24323 Ranks ITT``currency`Currency code`BDT``calling_code`Phone country code`+880``is_eu`EU member country`false`Detected Browsers
-----------------

[](#detected-browsers)

BrowserDetection MethodGoogle ChromeUser-Agent + Sec-CH-UAMozilla FirefoxUser-AgentSafariUser-AgentMicrosoft EdgeUser-Agent + Sec-CH-UAOpera / Opera GXUser-AgentBraveUser-Agent + Sec-CH-UAVivaldiUser-AgentTor BrowserUser-AgentKahf BrowserX-Requested-With headerDuckDuckGo BrowserX-Requested-With + User-AgentSamsung InternetUser-AgentUC BrowserUser-AgentInternet ExplorerUser-AgentChromiumUser-AgentDetected Mobile Brands &amp; Models
-----------------------------------

[](#detected-mobile-brands--models)

BrandModels DetectedAppleiPhone, iPad (with model number)SamsungGalaxy series, SM- model codesXiaomiRedmi, Mi, Poco seriesHuaweiHuawei, Honor seriesOnePlusAll OnePlus modelsOppoAll Oppo modelsVivoAll Vivo modelsGooglePixel seriesMotorolaMoto seriesNokiaAll Nokia modelsLGAll LG modelsSonyAll Sony modelsHTCAll HTC modelsDetected Robots &amp; Bots
--------------------------

[](#detected-robots--bots)

Googlebot, Bingbot, Yahoo Slurp, DuckDuckBot, Baiduspider, YandexBot, Sogou, Exabot, facebot, ia\_archiver, Facebookbot, Twitterbot, LinkedInBot, WhatsApp, Telegram, Discordbot, Slackbot, Applebot, AhrefsBot, SemrushBot, MJ12bot, DotBot, Screaming Frog, SEOkicks, and more.

Detected Platforms / Operating Systems
--------------------------------------

[](#detected-platforms--operating-systems)

Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Vista, Windows XP, macOS, iOS (iPhone), iOS (iPad), iPadOS, Android, Ubuntu, Linux, Chrome OS, BlackBerry, Windows Phone.

Configuration
-------------

[](#configuration)

Full `config/laratrack.php`:

```
return [
    // Tor Detection
    'enable_tor_detection' => env('LARATRACK_TOR_DETECTION', true),
    'tor_cache_duration'   => env('LARATRACK_TOR_CACHE', 3600),
    'tor_exit_node_url'    => env('LARATRACK_TOR_URL', 'https://check.torproject.org/exit-addresses'),

    // Robot Detection
    'enable_robot_detection' => env('LARATRACK_ROBOT_DETECTION', true),

    // IP Geolocation
    'enable_ip_geolocation'         => env('LARATRACK_GEO_ENABLED', false),
    'ip_geolocation_api_key'        => env('LARATRACK_GEO_API_KEY', ''),
    'ip_geolocation_api_url'        => env('LARATRACK_GEO_URL', 'https://api.ipgeolocation.io/v3/ipgeo'),
    'ip_geolocation_cache_duration' => env('LARATRACK_GEO_CACHE', 3600),

    // Events
    'fire_events' => env('LARATRACK_FIRE_EVENTS', true),

    // Country Blocking
    'blocked_countries' => [],

    // Middleware Messages & Redirects
    'middleware' => [
        'bot_message'          => 'Access denied: bots are not allowed.',
        'tor_message'          => 'Access denied: Tor connections are not allowed.',
        'vpn_message'          => 'Access denied: VPN/Proxy connections are not allowed.',
        'country_message'      => 'Access denied: your country is not allowed.',
        'mobile_only_message'  => 'This page is only available on mobile devices.',
        'desktop_only_message' => 'This page is only available on desktop.',
        'mobile_redirect'      => null,
        'desktop_redirect'     => null,
    ],
];
```

Requirements
------------

[](#requirements)

PHP VersionSupported8.1✅8.2✅8.3✅8.4✅8.5+✅ (future-compatible via `^8.1`)Laravel VersionSupported10.x✅11.x✅12.x✅13.x✅Testing
-------

[](#testing)

```
composer test
```

36 tests · 86 assertions · all passing ✅

API Routes (Non-Production Only)
--------------------------------

[](#api-routes-non-production-only)

```
GET /laratrack/test

```

Returns JSON with full detection data including headers. Disabled automatically in production.

Security
--------

[](#security)

If you discover any security issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Syed Sajid Akram](https://github.com/sajidwarner) — Package Author &amp; Maintainer
- [Claude.ai](https://claude.ai) — AI Assistant by Anthropic
- [ChatGPT](https://chat.openai.com/) — AI Assistant by OpenAI
- [Google Gemini](https://gemini.google/) — AI Assistant by Google

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Support
-------

[](#support)

For support, please open an issue on [GitHub](https://github.com/sajidwarner/laratrack).

---

**Keywords:** laratrack, laravel device detector, laravel browser detection, laravel user agent parser, laravel mobile detection, laravel ip geolocation, laravel bot detection, laravel tor detection, laravel vpn detection, laravel middleware, php device detection, laravel package

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance87

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~17 days

Recently: every ~0 days

Total

12

Last Release

62d ago

PHP version history (3 changes)v1.0.0PHP ^8.1|^8.2|^8.3

v1.0.5PHP ^8.1|^8.2|^8.3|^8.4

v1.1.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/95d56fad87dfe210e91b44ce4cefac17fb18bd8a969e6bcf554ce0a237560b09?d=identicon)[sajidwarner](/maintainers/sajidwarner)

---

Top Contributors

[![sajidwarner](https://avatars.githubusercontent.com/u/42565206?v=4)](https://github.com/sajidwarner "sajidwarner (16 commits)")

---

Tags

phplaravelgeolocationlaravel-packagemobile detectoruser agentbrowser detectionip geolocationdevice detectorbot-detectionmobile-detectiontor detectionDevice detectionUser agent parserbrowser-detectorclient-hintsplatform-detectionrobot detectionlaratrackuser-agent-detectortablet-detectionsec-ch-ua

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sajidwarner-laravel-device-detector/health.svg)

```
[![Health](https://phpackages.com/badges/sajidwarner-laravel-device-detector/health.svg)](https://phpackages.com/packages/sajidwarner-laravel-device-detector)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[toin0u/geocoder-laravel

Geocoder Service Provider for Laravel

7615.4M17](/packages/toin0u-geocoder-laravel)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k91.9k1](/packages/mike-bronner-laravel-model-caching)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)[ntanduy/cloudflare-d1-database

Cloudflare D1 database driver for Laravel — full Eloquent &amp; Query Builder support.

267.8k](/packages/ntanduy-cloudflare-d1-database)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
