ruvelo / laravel-device
Device, browser, OS and bot detection for Laravel, with User-Agent Client Hints and a drop-in replacement for jenssegers/agent.
Requires
- php: ^8.3
- laravel/framework: ^12.4.1|^13.0
- mobiledetect/mobiledetectlib: ^4.11
Requires (Dev)
- filament/widgets: ^4.14|^5.0
- larastan/larastan: ^3.13
- laravel/pint: ^1.32
- laravel/pulse: ^1.4
- orchestra/testbench: ^10.0|^11.0
- phpunit/phpunit: ^11.5|^12.0
Suggests
- filament/widgets: Shows the Insights counters in a Filament panel (Ruvelo\Device\Integrations\Filament\InsightsWidget).
- laravel/pulse: Shows the Insights counters on your Pulse dashboard (<livewire:device.insights />).
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-05 10:17:05 UTC
README
Live demo Configuration Bot verification Insights Developer guide Changelog
Laravel Device
Tells you what's on the other end of a request: the device, browser, operating system, and whether it's a bot.
Quick start
composer require ruvelo/laravel-device
Then ask:
$device = $request->device(); $device->type; // DeviceType::Phone $device->browser->name; // "Samsung Internet" $device->isBot; // false
That's it. There's nothing to publish, migrate or configure. In Blade, @mobile … @endmobile works straight away too.
Coming from jenssegers/agent? Change the import from Jenssegers\Agent to Ruvelo\Device; see Moving from jenssegers/agent.
What you get
- The device type: desktop, phone, tablet, TV, games console, watch or bot.
- The browser, operating system and engine, with versions.
- The maker and model, when the browser gives them away.
- Bots, sorted by what they're for: search engines, AI crawlers, link previews, SEO tools and more.
- Blade directives:
@mobile,@phone,@tablet,@desktop,@bot. - A drop-in
Agentclass with the same methods and answers as jenssegers/agent. - Fast (about 50 µs per new User-Agent) and small (one dependency).
Try it on 34 real visitors in the live demo.
Optional features
All of these are off by default. Nothing changes until you switch one on.
Bot verification
Checks that "Googlebot" really is Google, against the IP ranges each operator publishes. Off until you sync the ranges: run php artisan device:sync-bot-ranges once and schedule it weekly, then call Device::bot()->isVerified(). Details.
AI crawler rules and robots.txt
Allow, block or throttle AI crawlers and other bots by category. Off by default (every bot is allowed): set the rules under ai in config/device.php and add the device.ai middleware. php artisan device:robots writes the matching robots.txt. Details.
Detailed Client Hints
The package already reads the hints browsers send on their own. To ask Chromium browsers for the detailed ones (Windows 11, the real Android model), set DEVICE_CLIENT_HINTS_SEND=true. Off by default. Details.
Insights, Pulse and Filament
Counts what visits your site each day (people, search engines, AI crawlers) without storing anything personal. Off by default: set DEVICE_INSIGHTS=true, then read it with php artisan device:report, a Pulse card or a Filament widget. Details.
Bot list updates
Picks up new bots between package releases. Never runs on its own: run or schedule php artisan device:update. Details.
A quick tour
One typed answer per visitor. $request->device() gives you an immutable object: the device type as an enum, browser and system with versions, the engine, the maker and model when the browser tells, and what kind of bot it is, if it is one.
$device = $request->device(); $device->type; // DeviceType::Phone $device->browser->name; // "Samsung Internet" $device->os->atLeast(15); // true $device->model; // "SM-S938B" $device->isAiBot(); // false
Is that really Googlebot? Anyone can send its User-Agent. Ask the operator's published IP ranges instead, and decide what AI crawlers may do in one place:
Device::bot()->isVerified(); // true, false for an impostor, null when it can't be told // config/device.php 'ai' => ['policies' => ['ai-crawler' => 'block', 'ai-assistant' => 'throttle:30'], 'only_verified' => true],
Moving from jenssegers/agent is one line. Same methods, same return values, its own test suite passing. Then move to the typed API at your own pace.
![]() |
![]() |
| The demo is rendered by the package at build time, light and dark. | It's also a quick way to check a User-Agent: every row is a real one. |
Full feature list
- Device types: desktop, phone, tablet, TV, games console, wearable, bot or unknown, as a
DeviceTypeenum. TVs and consoles are no longer "desktops". - Browsers: Chrome, Edge, Firefox, Safari, Opera, Samsung Internet, Brave, Vivaldi, Yandex, DuckDuckGo, UC, Silk, Huawei, MIUI and others, plus in-app browsers (Instagram, Facebook, TikTok, WeChat) and Android web views. Edge and the other Chromium browsers are never mistaken for Chrome.
- Operating systems: Windows (10 vs 11 with Client Hints), macOS, iOS, iPadOS, Android, Fire OS, HarmonyOS, Chrome OS, Linux distributions, KaiOS, Tizen, webOS and more, with versions.
- Engines: Blink, WebKit, Gecko, EdgeHTML, Trident, Presto.
- Maker and model for Android phones and tablets, iPhones, iPads, Macs, TVs and consoles, when the User-Agent or Client Hints give it away.
- Bots, sorted by what they're for: search engines, AI training crawlers, AI search, AI assistants fetching for a person, link previews, SEO tools, monitors, feed readers, archivers and HTTP clients. GPTBot, ClaudeBot, PerplexityBot, Google-Extended, Bytespider, CCBot, Meta-ExternalAgent and friends included.
- User-Agent Client Hints:
Sec-CH-UA,-Mobile,-Platform,-Platform-Version,-Model,-Full-Version-List,-Form-Factors,-Archand-Bitness, used when present, plus a middleware (or one config switch) that asks browsers for them. - Bot verification:
Device::bot()->isVerified()checks Googlebot, Bingbot, GPTBot, ClaudeBot, Applebot, PerplexityBot, CCBot, Amazonbot and others against the IP ranges their operators publish (synced weekly by a command), and optionally by reverse and forward DNS. No network call during a request unless you turn DNS on. - AI crawler rules: allow, block (403) or throttle (429) training crawlers, AI search, AI assistants and search engines by category or by name, and block bots that fail verification, with the
device.aimiddleware.php artisan device:robotswrites the matchingrobots.txt(with the tokens operators document, such as Google-Extended) and anllms.txtstub. - Insights: what's visiting (opt-in): daily counts of humans and each kind of bot, in your cache or one small table, with
php artisan device:report, a Laravel Pulse card and a Filament widget. No IP addresses, User-Agents or URLs are kept. - Bot list updates between releases:
php artisan device:updatedownloads the latest list from this repository, checks its SHA-256 checksum and contents, and uses it only while it's newer than the one built in. Never runs unless you run or schedule it. - iPads that pretend to be Macs: recognised when the browser gives it away, and flagged as "might be an iPad" when it doesn't. An optional one-line script settles it.
- Blade directives:
@mobile,@phone,@tablet,@desktop,@bot,@device('tv', 'console'), each with its@elseand@unlessforms. - Fast: about 50 µs to parse a new User-Agent, and each answer is remembered for the rest of the process (or in your cache store, if you like).
- Small: one runtime dependency, Mobile Detect, for the long tail of phones and tablets.
- Drop-in for jenssegers/agent:
Ruvelo\Device\Agent, theAgentfacade and alias, magicisIphone()methods and all.
Moving from jenssegers/agent
This package is the maintained successor to jenssegers/agent, which has had no release since June 2020. The Agent class keeps its method names and answers, so switching is a change of import.
- composer require jenssegers/agent + composer remove jenssegers/agent && composer require ruvelo/laravel-device
- use Jenssegers\Agent\Agent; + use Ruvelo\Device\Agent; - use Jenssegers\Agent\Facades\Agent; + use Ruvelo\Device\Facades\Agent;
The package registers the Agent alias too, so Agent::isMobile() in Blade keeps working without changes. app('agent'), new Agent() and new Agent($headers, $userAgent) behave as before. jenssegers/agent's own test suite runs, unchanged, in tests/Unit/JenssegersCompatibilityTest.php.
| jenssegers/agent | Here | Typed API |
|---|---|---|
isMobile() |
Same (phones and tablets) | $device->isMobile() |
isTablet(), isPhone() |
Same | $device->isTablet(), isPhone() |
isDesktop() |
Same; false for TVs, consoles and watches | $device->isDesktop() |
isRobot(), robot() |
Same, with AI crawlers | $device->isBot, botName, botCategory |
browser() |
Same names ("Chrome", "IE", "Edge"...) plus new ones ("Samsung Internet", "Brave") | $device->browser->name |
platform() |
Same names ("Windows", "OS X", "AndroidOS", "iOS") | $device->os->name ("macOS", "Android", "iPadOS") |
version($name) |
Same; full browser version from Client Hints | $device->browser->version, $device->os->version |
device() |
Same (Mobile Detect's names: "iPhone", "Nexus", "Macintosh") | $device->brand, $device->model |
deviceType() |
Same ("desktop", "phone", "tablet", "robot", "other") | $device->type |
languages() |
Same | $device->languages |
is('Windows'), isIphone() |
Same | $device->os->is('Windows') |
match($regex) |
Same | |
setUserAgent(), setHttpHeaders(), getUserAgent() |
Same | Device::fromUserAgent($ua, $headers) |
toDevice() |
the typed object for this agent |
What changed, on purpose:
- Browser checks are exact.
isChrome()is false on Edge, Opera, Samsung Internet and Brave;isSafari()is false on Chrome.browser()names Samsung Internet, Yandex, DuckDuckGo and the in-app browsers instead of calling them Chrome or Safari. - iPads asking for desktop sites are tablets when the browser gives it away (Chrome, Firefox and Edge for iPad say so), and with
@detectIpad. - TVs, consoles and watches are no longer desktops.
deviceType()calls them "other". - Robots come from this package's own list instead of jaybizzle/crawler-detect. It's shorter but current, and sorted into categories; anything calling itself a bot, crawler or spider is still caught. If you depended on an obscure crawler being named, check
robot()for it. - Client Hints are read when the browser sends them.
- One Agent per request, so it's safe under Octane.
Blade
@mobile <a href="/app">Get the app</a> @elsebot {{-- crawlers get the plain page --}} @else <a href="/download">Download for desktop</a> @endmobile @device('tv', 'console') <p>Use your remote: arrows and OK.</p> @enddevice
@mobile means phones and tablets, as in jenssegers/agent; use @phone for phones only. Every directive has @else…, @unless… and @end… forms. To use $device in every view, add the device.share middleware (device.share:visitor names the variable $visitor).
iPads
Since iPadOS 13, Safari on an iPad asks for desktop sites with exactly the same User-Agent as Safari on a Mac. No server-side library can tell them apart from the request alone. This package:
- recognises iPads whenever the browser gives it away: Chrome, Firefox, Edge and Opera for iPad keep their iOS names (
CriOS,FxiOS...) in the Mac User-Agent; - otherwise reports a desktop Mac, with
$device->mightBeIpadset totruefor Safari, so you can hedge; - offers
@detectIpad, a one-line inline script for your layout's<head>. On a "Mac" with a touch screen (Macs have none) it sets adevice_ipadcookie, and from the next request on the visitor is an iPad running iPadOS, with the version taken from Safari's own version number. The cookie is excluded from Laravel's cookie encryption automatically. The script uses Vite's CSP nonce when you've set one.
The very first page view of an iPad in desktop mode is still a Mac. That's a limit of the web platform, not something a parser can fix.
Two more frozen values: since iOS 26, Safari's User-Agent says iOS 18.6 whatever the real version; the package reads the version from Safari's Version/26.0 instead. Macs always say 10.15.7 without Client Hints.
Bots
$device->isBot; // true $device->botName; // "ClaudeBot" $device->botCategory; // BotCategory::AiCrawler $device->isAiBot(); // true for AiCrawler, AiSearch and AiAssistant
| Category | Who |
|---|---|
Search |
Googlebot, Bingbot, DuckDuckBot, Applebot, YandexBot, Baiduspider, PetalBot... |
AiCrawler |
GPTBot, ClaudeBot, MistralAI-Training, CCBot, Bytespider, Google-Extended, Applebot-Extended, Meta-ExternalAgent, Amazonbot, cohere-ai, Diffbot... |
AiSearch |
OAI-SearchBot, Claude-SearchBot, PerplexityBot, Amzn-SearchBot, Meta-WebIndexer, MistralAI-Index, YouBot... |
AiAssistant |
ChatGPT-User, Claude-User, Perplexity-User, MistralAI-User, DuckAssistBot, Amzn-User, Meta-ExternalFetcher: one page, fetched because a person asked. Also browsers an AI agent drives for a person, which add their own token to a real browser's User-Agent (Claude-Agent, Google-Agent) |
Social |
facebookexternalhit, Twitterbot, LinkedInBot, Slackbot, Discordbot, WhatsApp, Mastodon... |
Seo, Monitoring, Feed, Archiver |
AhrefsBot, SemrushBot; UptimeRobot, Pingdom, Lighthouse; Feedly; the Internet Archive... |
Tool |
curl, Wget, python-requests, Go-http-client, Guzzle, Postman, HeadlessChrome... |
Other |
anything else that calls itself a bot, crawler or spider |
A User-Agent is only a claim: anyone can send "Googlebot". If you grant crawlers anything, verify them. Google-Extended and Applebot-Extended are robots.txt names; their owners crawl as Googlebot and Applebot, so expect them only from impostors.
Keeping the bot list current
New AI crawlers appear every month. Between package releases, php artisan device:update fetches the list published in this repository (resources/bots.json) and stores it in storage/app/device/bots.json:
php artisan device:update # download, check and store, if newer
php artisan device:update --status # which list is in use
php artisan device:update --reset # delete the download, back to the built-in list
Before anything is stored, the download must match its published SHA-256 checksum (bots.json.sha256), be in a format this version reads, have only patterns that compile, and still file Googlebot, GPTBot and ChatGPT-User correctly while leaving Chrome, Safari and Samsung Internet alone. Anything wrong leaves the current list in place and the command exits non-zero. A stored list is used only while it's newer than the one built into the package, so composer update always wins, and a missing or damaged file falls back to the built-in list silently.
It never runs by itself: schedule it if you want it. Under Octane or a queue worker, restart the workers after an update; they read the list once.
Client Hints
Chromium browsers (Chrome, Edge, Opera, Samsung Internet, Brave...) have frozen their User-Agent: every Windows is "Windows NT 10.0", every Mac "10_15_7", every Android phone "Android 10; K", and the browser version ends in ".0.0.0". The real details moved to Sec-CH-UA-* request headers.
Three of them arrive on every HTTPS request, and the package uses them as soon as they're there: the brand (so Brave and Opera are recognised), whether the device is mobile, and the platform. For the rest, ask with the device.hints middleware:
// bootstrap/app.php ->withMiddleware(function (Middleware $middleware) { $middleware->web(append: \Ruvelo\Device\Http\Middleware\RequestClientHints::class); })
or per route with ->middleware('device.hints'), or set DEVICE_CLIENT_HINTS_SEND=true to have the package append it to the web group for you. It's off by default. It sends Accept-CH, and browsers include the hints from the next request on: Windows 10 vs 11, the macOS and Android version, the phone model, the full browser version and the form factor. Pass hints to the alias to pick your own: device.hints:Sec-CH-UA-Model.
For a response built outside the middleware stack, add the headers yourself:
use Ruvelo\Device\Http\Middleware\RequestClientHints; return RequestClientHints::apply(response()->view('home'), ['Sec-CH-UA-Model', 'Sec-CH-UA-Platform-Version']);
What each hint changes:
| Hint | Sent | Gives you |
|---|---|---|
Sec-CH-UA |
always | The real brand (Brave, Opera, Edge) and major version |
Sec-CH-UA-Mobile, -Platform |
always | Phone or tablet on Android; the operating system |
Sec-CH-UA-Platform-Version |
when asked | Windows 11 (13.0.0 and above) vs 10 (1.0.0 to 10.0.0), as Microsoft documents; the real macOS and Android versions |
Sec-CH-UA-Model |
when asked | The Android model ("Pixel 3 XL") and maker, instead of the reduced "K" |
Sec-CH-UA-Full-Version-List |
when asked | The full browser version ("141.0.7390.66") instead of "141.0.0.0" |
Sec-CH-UA-Form-Factors |
when asked | Tablet, phone or watch |
Sec-CH-UA-Arch, -Bitness |
when asked | $device->architecture ("x86", "arm") and $device->bitness ("64") |
$device->usedClientHints tells you whether hints changed the answer.
Good to know:
- Browsers only send hints over HTTPS (and to
localhost). - The first request of a visit only has the three basic hints. List a hint in
client_hints.criticalto have the browser retry that first request with it; that costs a round trip, once. - Safari and Firefox don't send Client Hints. For them the User-Agent is still the source, and it hasn't been frozen the same way, except where noted below.
- If a CDN caches pages that differ by device, add the hints you rely on to the
Varyheader.
Verifying bots
use Ruvelo\Device\Device; $bot = Device::bot(); // the current request; or Device::bot($request), or $request->bot() $bot->name; // "Googlebot" $bot->isVerified(); // true: the IP is in Google's published ranges // false: Google publishes ranges and this IP isn't in them // null: no published method, ranges not synced yet, or not a bot $bot->isSpoofed(); // true when isVerified() is false $bot->verification()->toArray(); // ['status' => 'verified', 'method' => 'ip-range', 'matched' => '66.249.64.0/27', // 'operator' => 'Google', 'sources' => [...], 'reason' => '...', ...]
How it works:
php artisan device:sync-bot-rangesdownloads the IP range files operators publish and stores them in one PHP file (storage/app/device-bot-ranges.php), so a check is an in-memory CIDR match, IPv4 and IPv6. Schedule it weekly. A file that fails to download keeps its previous ranges, and the command exits non-zero so the scheduler can tell you.--only=Google --only=GPTBotsyncs some sources.- During a request nothing touches the network, unless you set
bots.verification.dnstotrue. Then an IP not in the ranges, or an operator verified by DNS only (Yandex), is checked by reverse DNS, a domain check and a forward lookup back to the same IP. Answers are cached for a day. nullis deliberate. Meta, for instance, documents its crawlers' User-Agents but no IP list or hostname, so a Meta crawler can't be verified either way. Before the first sync, everything isnulltoo, so nothing gets blocked by accident.- The IP is
$request->ip(). Behind a load balancer or CDN, trust your proxies, or every request will look like it comes from them. - Verification statuses:
Verified,Spoofed,Unverifiable(no published method),Unknown(method exists but couldn't be applied) andNotABot, in theRuvelo\Device\Bots\VerificationStatusenum.
What each operator publishes, and what the package uses (all from the operators' own documentation, checked December 2026):
| Bots | IP ranges | Reverse DNS | Documentation |
|---|---|---|---|
| Googlebot, Google-InspectionTool, GoogleOther, Storebot-Google, Google-CloudVertexBot | common-crawlers.json | googlebot.com |
Verifying Google's crawlers |
| AdsBot-Google, Mediapartners-Google | special-crawlers.json | google.com |
same |
| FeedFetcher-Google, Google-Read-Aloud, Google-Site-Verification, APIs-Google, Google-GeminiNotebook | user-triggered-fetchers.json, user-triggered-fetchers-google.json | gae.googleusercontent.com, google.com |
same |
| Google-Agent | user-triggered-agents.json | Google's user-triggered fetchers | |
| Bingbot | bingbot.json | search.msn.com |
How to verify that Bingbot is Bingbot |
| GPTBot, OAI-SearchBot, ChatGPT-User, OAI-AdsBot | gptbot.json, searchbot.json, chatgpt-user.json, adsbot.json | OpenAI's crawlers | |
| ClaudeBot, Claude-User, Claude-SearchBot | bots.json | Anthropic's crawlers | |
| Claude-Agent | sail (its Claude-Agent service) |
Anthropic's hosted browsers | |
| Applebot | applebot.json | applebot.apple.com |
About Applebot |
| PerplexityBot, Perplexity-User | perplexitybot.json, perplexity-user.json | Perplexity crawlers | |
| DuckDuckBot, DuckAssistBot | duckduckbot.json, duckassistbot.json | DuckDuckBot, DuckAssistBot | |
| CCBot | ccbot.json | crawl.commoncrawl.org |
CCBot |
| Amazonbot, Amzn-SearchBot, Amzn-User | lists on ip-addresses, searchbot-ip-addresses, live-ip-addresses | Amazonbot | |
| MistralAI-User, MistralAI-Index | mistralai-user-ips.json, mistralai-index-ips.json | Mistral AI robots | |
| YandexBot | yandex.ru, yandex.net, yandex.com |
Checking Yandex robots |
Not verifiable (null), because the operator publishes no method: Meta's crawlers (Meta-ExternalAgent, Meta-ExternalFetcher, Meta-WebIndexer, facebookexternalhit), MistralAI-Training, Anthropic's retired Claude-Web and anthropic-ai, and every bot not in the table. The list lives in src/Bots/Operators.php; a pull request with the operator's documentation link is all it takes to add one.
AI crawler rules
One config decides what each kind of bot may do, and both the middleware and the generated robots.txt follow it:
// config/device.php 'ai' => [ 'policies' => [ 'ai-crawler' => 'block', // training crawlers: GPTBot, ClaudeBot, CCBot, Bytespider... 'ai-search' => 'allow', // AI search indexers: OAI-SearchBot, PerplexityBot... 'ai-assistant' => 'throttle:30', // fetches a person asked for: ChatGPT-User, Claude-User... 'search' => 'allow', // Googlebot, Bingbot... 'others' => 'allow', // every other category (link previews, SEO tools, curl...) ], 'bots' => ['Amazonbot' => 'allow'], // by name, overriding the category 'only_verified' => ['search', 'ai-crawler', 'ai-search'], // impostors get a 403 // ... ],
// bootstrap/app.php: every web route ->withMiddleware(function (Middleware $middleware) { $middleware->web(append: \Ruvelo\Device\Http\Middleware\ApplyAiRules::class); }) // or per route Route::middleware('device.ai')->group(...);
blockanswers 403,throttleanswers 429 withRetry-Afterpast the limit (requests a minute, counted per bot, with Laravel's rate limiter). Visitors that aren't bots are never touched.only_verifieduses bot verification: a bot whose operator publishes ranges and whose IP isn't in them is blocked. Bots that can't be verified (null) pass, so sync the ranges first.- With the defaults every bot is allowed, so adding the middleware changes nothing until you configure it.
robots.txtandllms.txtare never blocked (ai.except), so blocked crawlers can read why.- Google-Extended and Applebot-Extended never send requests of their own (Google and Apple train on what Googlebot and Applebot fetch), so the middleware can't block them without blocking search. Say it in
robots.txt, which is what they read.
robots.txt and llms.txt
php artisan device:robots # print the robots.txt rules
php artisan device:robots --write # write public/robots.txt (--force to overwrite)
php artisan device:robots --llms # print an llms.txt stub
php artisan device:robots --llms --write # write public/llms.txt
With the config above it prints:
# Generated by ruvelo/laravel-device from config/device.php (device.ai).
# AI crawler (ai-crawler)
User-agent: GPTBot
User-agent: MistralAI-Training
User-agent: ClaudeBot
...
User-agent: Google-Extended
User-agent: Applebot-Extended
User-agent: CCBot
...
Disallow: /
User-agent: *
Disallow:
Bots are named by the robots.txt token their operator documents, which isn't always their User-Agent name: Google-Extended, Applebot-Extended, bingbot, Yandex, AdsBot-Google (which ignores User-agent: *), facebookexternalhit. Only block can be said in robots.txt; throttling and verification are the middleware's job. Fetchers acting for a person that their operators say ignore robots.txt (Google's user-triggered fetchers, Claude-Agent) are left out. Add your own paths with ai.robots.disallow and your sitemap with ai.robots.sitemap.
Set ai.routes to true to serve both files from the config instead, always in sync with it. Delete public/robots.txt then: the web server answers before Laravel does. The llms.txt stub (llmstxt.org) takes its title, summary and links from ai.llms.
Insights: what's visiting
How much of your traffic is people, and how much is search engines, AI crawlers or HTTP scripts? Turn on Insights and the package counts every web request into a daily bucket:
DEVICE_INSIGHTS=true
| Bucket | Counts |
|---|---|
human |
Browsers that aren't bots |
bot:search, bot:ai-crawler, bot:ai-search, bot:ai-assistant, bot:social, bot:seo, bot:monitoring, bot:feed, bot:archiver, bot:tool |
Each bot category |
bot:other |
Unlisted bots: anything else that says it's a bot, crawler or spider |
unknown |
No User-Agent, or one nothing can be made of |
Cheap, and nothing personal. Each request adds one to a counter, after the response is sent where the server allows it. The default driver uses your cache (one key per day and bucket, expiring after keep_days); database keeps one row per day and bucket in a small table. Only the date, the bucket name and the number are stored: no IP addresses, User-Agents, URLs or cookies. On busy sites, set DEVICE_INSIGHTS_SAMPLE_RATE=0.1 to count one request in ten, ten times over. If the store fails, the request carries on and the error is reported once.
Read them from the command line:
php artisan device:report # the last 7 days
php artisan device:report --days=30
php artisan device:report --json
+------------+--------+---------------+------------+-----+
| Day | Humans | Search engine | AI crawler | All |
+------------+--------+---------------+------------+-----+
| 2026-12-02 | 40 | 3 | 0 | 43 |
| 2026-12-03 | 50 | 2 | 10 | 62 |
| Total | 90 | 5 | 10 | 105 |
+------------+--------+---------------+------------+-----+
Humans 86%, bots 14% (AI 10%).
or in code:
use Ruvelo\Device\Insights\Insights; $report = app(Insights::class)->report(days: 7); $report->humans(); // 90 $report->aiBots(); // 10 $report->totals(); // ['human' => 90, 'bot:search' => 5, 'bot:ai-crawler' => 10] $report->series('ai'); // [0, 10]: per day, oldest first ('humans', 'bots', 'ai' or a bucket)
Verified and unverified bots. Out of the box, Insights asks the package's own bot verification about each bot and counts it as bot:search:verified or bot:search:unverified (an impostor), and so on. That starts once there's something to check against: synced IP ranges (device:sync-bot-ranges) or DNS checks (bots.verification.dns). Before that, and for bots whose operator publishes no method (Meta's, for instance), the bucket stays plain bot:search. Set insights.verify_bots to false to never split. To use your own check instead, return true, false or null (can't tell):
// AppServiceProvider::boot() use Illuminate\Http\Request; use Ruvelo\Device\Device; use Ruvelo\Device\Insights\Insights; app(Insights::class)->verifyBotsUsing( fn (Device $device, ?Request $request): ?bool => $device->botName === 'Googlebot' ? $request?->bot()->isVerified() : null, );
The check runs after the response is sent; with DNS checks on, their answers are cached. Only the result is counted: the IP address is never stored.
To count only some routes, set insights.middleware_groups to [] and add the device.insights middleware where you want it.
Integrations: Pulse and Filament
Both read the same counters as device:report, and both are optional: the package doesn't require Pulse or Filament, and their classes are only loaded when you use them.
Laravel Pulse (1.4+). With Pulse installed, the card is registered as a Livewire component. Add it to your published dashboard (resources/views/vendor/pulse/dashboard.blade.php):
<livewire:device.insights cols="4" />
It shows humans, bots and AI bots, then every bucket with its share, over the dashboard's period rounded up to whole days.
Filament (4.14+ or 5). Add the widget to a panel or a page:
use Ruvelo\Device\Integrations\Filament\InsightsWidget; $panel->widgets([InsightsWidget::class]);
It shows humans, bots, AI bots and search engines over the last 7 days, each with a daily sparkline. Extend it and set protected int $days = 30; for another range.
For developers
PHP API
use Ruvelo\Device\Device; use Ruvelo\Device\DeviceType; $device = $request->device(); // the request macro $device = Device::fromRequest(); // the current request $device = Device::fromUserAgent($ua); // any string, e.g. from your logs $device = Device::fromUserAgent($ua, $headers); // with Sec-CH-UA-*, Accept-Language... in any common shape $device->is('mobile'); // phones and tablets $device->is(DeviceType::Tv, 'console'); // any of these $device->browser->is('firefox'); // case-insensitive name check $device->browser->major(); // 143 (string) $device->os; // "Windows 11" $device->language(); // "fr-be" $device->toArray(); // see below $bot = Device::bot(); // or $request->bot(): the bot, with verification $bot->isVerified(); // true, false or null
| Property | Type | |
|---|---|---|
type |
DeviceType |
Desktop, Phone, Tablet, Tv, Console, Wearable, Bot, Unknown |
browser, os, engine |
Browser, OperatingSystem, Engine |
Each with name and version (strings or null), major(), atLeast(), is(), known() |
brand, model |
?string |
"Apple"/"iPhone", "Samsung"/"SM-S938B", "Sony"/"PlayStation 5" |
isBot, botName, botCategory |
bool, ?string, ?BotCategory |
|
languages |
list<string> |
From Accept-Language, most preferred first, lowercased |
usedClientHints |
bool |
Whether Client Hints changed the answer |
architecture, bitness |
?string |
"x86"/"arm" and "64"/"32", from Sec-CH-UA-Arch and -Bitness only; null otherwise |
mightBeIpad |
bool |
Safari on a Mac, which might be an iPad in desktop mode |
userAgent |
string |
What was parsed |
JSON
Device is JsonSerializable, so return $request->device(); or response()->json($device) gives React, Vue and Inertia apps the same answer:
{
"type": "phone",
"browser": { "name": "Samsung Internet", "version": "28.0" },
"os": { "name": "Android", "version": "15" },
"engine": { "name": "Blink", "version": "130.0.0.0" },
"brand": "Samsung",
"model": "SM-S938B",
"is_bot": false,
"bot": null,
"languages": ["en-gb"],
"used_client_hints": false,
"might_be_ipad": false,
"user_agent": "Mozilla/5.0 (Linux; Android 15; SM-S938B) ..."
}
For bots, bot is {"name": "GPTBot", "category": "ai-crawler"}. When the browser sent Sec-CH-UA-Arch or -Bitness, architecture and bitness are added after user_agent. Device::fromArray() reads it all back.
Middleware
| Alias | Class | Does |
|---|---|---|
device.share |
Http\Middleware\ShareDevice |
Shares $device (or the name you pass) with every view |
device.hints |
Http\Middleware\RequestClientHints |
Sends Accept-CH (and Critical-CH) to ask for Client Hints. Added to web by client_hints.send |
device.ai |
Http\Middleware\ApplyAiRules |
Allows, blocks or throttles bots by the ai config |
device.insights |
Http\Middleware\CountVisits |
Counts the request for Insights when insights.enabled is on. Added to insights.middleware_groups automatically |
Commands
| Command | Does |
|---|---|
device:sync-bot-ranges |
Downloads the operators' IP ranges for bot verification. --only= picks sources, operators or bots. Schedule it weekly |
device:robots |
Prints robots.txt rules from the ai config; --llms for the llms.txt stub, --write (and --force, --path=) to write the file |
device:report {--days=7} {--json} |
Prints the Insights counters, one row per day |
device:update {--url=} {--force} {--status} {--reset} |
Downloads, checks and stores the latest bot list |
Events and exceptions
Detection changes nothing, so there are no events. Exceptions implement Ruvelo\Device\Exceptions\DeviceException: InvalidDeviceType (an unknown name passed to is() or @device), UnknownMethod (a magic method on Agent that doesn't start with "is"; still a BadMethodCallException, as before) and InvalidBotList (a bot list that fails its checks; device:update catches it and reports it).
In your tests
Ruvelo\Device\Testing\UserAgents holds real, current User-Agents, so you don't have to collect them:
use Ruvelo\Device\Testing\UserAgents; $this->withHeader('User-Agent', UserAgents::IPHONE)->get('/')->assertSee('Get the app'); $this->withHeader('User-Agent', UserAgents::GPTBOT)->get('/articles/1')->assertForbidden();
For bot verification, swap the DNS resolver so no test touches the network, and fake the operators' files with Http::fake() before running device:sync-bot-ranges:
use Ruvelo\Device\Bots\DnsResolver; use Ruvelo\Device\Testing\FakeDns; $this->app->instance(DnsResolver::class, new FakeDns( reverse: ['66.249.66.1' => 'crawl-66-249-66-1.googlebot.com'], forward: ['crawl-66-249-66-1.googlebot.com' => ['66.249.66.1']], ));
In production
- Proxies and CDNs: verification and per-bot throttling read
$request->ip(). Configure trusted proxies (Cloudflare, a load balancer) so it's the visitor's address. - Scheduler:
Schedule::command('device:sync-bot-ranges')->weekly(), as in Installation. Each server reads its own ranges file, so don't addonOneServer()unlessbots.verification.ranges_pathpoints at storage they share. Run it in your deploy script too, so a fresh server starts with ranges. - Octane and queues: the ranges file is re-read within a minute of a sync; nothing else is kept between requests.
- Route caching: the optional
/robots.txtand/llms.txtroutes use a controller, soroute:cachekeeps them. - Cache: throttling uses Laravel's rate limiter (the default cache store); DNS answers use
bots.verification.dns_cache_store; Insights counters useinsights.cache_store(or a table with thedatabasedriver). Counters are shared by every server using the same store. - Bot list updates:
device:updatewritesbot_list.pathon the server it runs on. With several servers, run it on each (or pointbot_list.pathat shared storage), and restart Octane or queue workers afterwards: they read the list once.
How detection works
The package keeps its own rule tables, in src/Detection, ordered from most to least specific: bots, browsers, operating systems, then TVs, consoles, wearables and Android makers. Client Hints override the User-Agent where they're more reliable. Mobile Detect (MIT, maintained) answers only what those tables don't recognise, the long tail of phones and tablets, and provides the device names behind Agent::device() and the magic isNexus()-style methods. It has no dependencies of its own beyond PSR-16, which Laravel already ships.
The bot rules are a versioned list (Detection/BotList) in one format for the built-in list and the downloaded one: {"schema": 1, "version": "2026.12.03", "rules": [{"pattern": ..., "name": ..., "category": ...}]}. The built-in list is written in PHP and exported to resources/bots.json by composer bots; a test fails if the two drift apart.
Each answer is kept in memory for the life of the process, up to 500 User-Agents, so long-running workers don't grow. Set cache.store to share answers between processes; entries are keyed by the rules' version and the bot list's version, so an update never serves stale answers.
Found a User-Agent it gets wrong? Open an issue with the string (and the Sec-CH-UA-* headers, if any), or add it to tests/Fixtures/user-agents.php in a pull request.
Laravel Boost
If your app uses Laravel Boost, php artisan boost:install picks up this package's guidelines, so your coding agent uses $request->device() instead of hand-written User-Agent regexes, branches on bot categories rather than names, and uses the test User-Agents.
Requirements
| Laravel | PHP | Tested in CI |
|---|---|---|
| 12 (12.4.1+) | 8.3, 8.4, 8.5 | yes |
| 13 | 8.3, 8.4, 8.5 | yes |
Bot verification needs no extension: device:sync-bot-ranges needs outbound HTTPS to the operators' sites, and the optional DNS checks use PHP's own resolver.
Optional, only for the Insights dashboards: Laravel Pulse 1.4+ and Filament 4.14+ or 5 (filament/widgets). Neither is required; the classes that use them are only loaded when you do.
Scheduled commands
composer require ruvelo/laravel-device is all device detection needs: the package registers itself. Two optional features use a scheduled command:
// routes/console.php use Illuminate\Support\Facades\Schedule; // Refresh the bot operators' IP ranges, for Device::bot()->isVerified() (and verified/unverified counts in Insights) Schedule::command('device:sync-bot-ranges')->weekly(); // If you want it: pick up new bots between package releases (it never runs on its own) Schedule::command('device:update')->daily();
Run php artisan device:sync-bot-ranges once now, so verification works before the first scheduled run. With DEVICE_INSIGHTS_DRIVER=database, Insights also needs its table: php artisan vendor:publish --tag=device-migrations && php artisan migrate.
Configuration reference
Everything works without configuration. To change the defaults:
php artisan vendor:publish --tag=device-config
| Key | Default | |
|---|---|---|
client_hints.read |
true (DEVICE_CLIENT_HINTS) |
Use Sec-CH-UA-* headers when the browser sends them |
client_hints.send |
false (DEVICE_CLIENT_HINTS_SEND) |
Append the device.hints middleware to the web group, so every page asks for the hints in request |
client_hints.request |
platform version, model, full version list, form factors | What the device.hints middleware asks for. Add Sec-CH-UA-Arch and Sec-CH-UA-Bitness for $device->architecture and bitness |
client_hints.critical |
[] |
Hints to also send as Critical-CH: the browser retries the first request with them |
insights.enabled |
false (DEVICE_INSIGHTS) |
Count visits per day by category. See Insights |
insights.middleware_groups |
['web'] |
Groups the device.insights middleware is appended to when enabled; [] to add it to routes yourself |
insights.driver |
cache (DEVICE_INSIGHTS_DRIVER) |
cache (one counter per day and bucket) or database (one small table; publish the migration) |
insights.cache_store |
null (DEVICE_INSIGHTS_CACHE_STORE) |
Cache store for the counters; the default store when null |
insights.connection |
null (DEVICE_INSIGHTS_DB_CONNECTION) |
Database connection for the database driver; the default when null |
insights.table |
device_insights |
Table for the database driver |
insights.sample_rate |
1.0 (DEVICE_INSIGHTS_SAMPLE_RATE) |
Share of requests counted. At 0.1, one request in ten is counted, ten times over |
insights.keep_days |
90 |
Counters older than this expire (cache) or are deleted now and then (database) |
insights.verify_bots |
true |
Split bot counts into verified and unverified with bot verification, once ranges are synced or DNS is on |
bot_list.path |
storage/app/device/bots.json (DEVICE_BOT_LIST_PATH) |
Where device:update stores the downloaded list; null ignores downloaded lists |
bot_list.url |
this repository's resources/bots.json on main (DEVICE_BOT_LIST_URL) |
Where device:update downloads from (https only; the checksum is read from the same URL plus .sha256) |
bot_list.timeout |
10 |
Seconds before a download gives up |
cache.store |
null (DEVICE_CACHE_STORE) |
A cache store to share answers between requests; memory only when null |
cache.ttl |
one week | How long cached answers live |
ipad_cookie |
device_ipad |
The cookie @detectIpad sets; null turns it off |
max_length |
1000 |
Longer User-Agents are cut before parsing |
blade_directives |
true |
Register @mobile and friends |
request_macro |
true |
Register $request->device() and $request->bot() |
bots.verification.ranges_path |
null (DEVICE_BOT_RANGES_PATH) |
Where device:sync-bot-ranges stores the ranges; storage/app/device-bot-ranges.php when null |
bots.verification.dns |
false (DEVICE_BOT_DNS) |
Also verify by reverse + forward DNS. Lookups block, so they are cached |
bots.verification.dns_cache_store |
null |
Cache store for DNS answers; the default store when null |
bots.verification.dns_cache_ttl |
one day | How long DNS answers are cached |
bots.verification.timeout |
15 |
Seconds per file when syncing ranges |
ai.policies |
everything allow |
Policy per bot category: ai-crawler, ai-search, ai-assistant, search, any other category, and others for the rest. allow, block, throttle or throttle:30 |
ai.bots |
[] |
Policies by bot name, overriding the category: ['GPTBot' => 'block'] |
ai.only_verified |
false |
Block bots that fail verification: true for every category, or a list such as ['search', 'ai-crawler'] |
ai.throttle |
60 |
Requests a minute for a plain throttle, counted per bot |
ai.except |
['robots.txt', 'llms.txt'] |
Paths the middleware never blocks |
ai.routes |
false |
Serve /robots.txt and /llms.txt from these rules |
ai.robots.disallow |
[] |
Paths to disallow for User-agent: * in the generated robots.txt |
ai.robots.sitemap |
null |
A sitemap URL (or a list) to add to it |
ai.llms.title, ai.llms.description, ai.llms.sections |
app name, none, a link to the home page | The generated llms.txt |
If you published the config before this release, the new top-level keys still apply with their defaults: Laravel merges the package's config under yours. Publish again (or copy the bots, ai, insights and bot_list blocks, and send into client_hints) to change them.
Upgrading
From 1.0
Nothing to do: every addition is opt-in, and the API, config keys and JSON shape of 1.0 are unchanged. Worth knowing:
- New config keys (
bots,ai,insights,bot_list,client_hints.send) apply with their defaults (everything allowed, DNS off, Insights off, Accept-CH not sent) even if you published the config before. Publish it again or copy those blocks to change them. - New API:
Device::bot(), the$request->bot()macro (off withrequest_macro, likedevice(); if your app already defines abotrequest macro, yours is kept), thedevice.aianddevice.insightsmiddleware aliases, and four commands (device:sync-bot-ranges,device:robots,device:report,device:update). - Verification needs
php artisan device:sync-bot-ranges, scheduled. It writesstorage/app/device-bot-ranges.php; nothing has to be migrated. Insights only needs a migration with thedatabasedriver. Devicegainsarchitectureandbitness(fromSec-CH-UA-Archand-Bitness). They'renullunless the browser sent those hints, andtoArray()/ JSON only include them when they're set.Sec-CH-UAGREASE brands with leading punctuation, like MDN's"(Not(A:Brand", are now ignored. A Chromium build that sends only that and"Chromium"used to come out as a browser named "(Not(A:Brand"; it's now "Chromium".- The bot list now lives in one format shared with downloads.
Bots::rules()returns the list in use; the built-in one isBots::builtInRules(). - Cached answers (with
cache.storeset) are keyed by the bot list's version too, so they're recomputed once after the upgrade, and again wheneverdevice:updatestores a newer list.
Contributing
Pull requests are welcome, and new User-Agents most of all. Clone, composer install, then composer check runs code style (Pint), static analysis (PHPStan level 8) and the tests, exactly as CI does. After changing the bot rules, bump BotList::BUILT_IN_VERSION and run composer bots to export them to resources/bots.json, which is what device:update downloads once merged. See CONTRIBUTING.md and the changelog.
The demo and screenshots are built from the package itself: composer demo writes the static demo into build/, and demo/screenshots.sh regenerates art/.
Credits
Built by François Bultez at Valtry, the website security scanner, and everyone who contributes.
Thanks to Jens Segers for jenssegers/agent, which served the Laravel community for a decade and whose API the Agent class keeps, and to Şerban Ghiţă and the contributors of Mobile Detect.
License
MIT. See LICENSE.




