Download the PHP package ruvelo/laravel-device without Composer

On this page you can find all versions of the php package ruvelo/laravel-device. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-device

Live demo     Configuration     Developer guide     Changelog

Tests Laravel 12 | 13 PHP 8.3+ PHPStan level 8

Laravel Device

Know who's on the other end. Phones, tablets, TVs, consoles and watches; browsers, operating systems and engines; search engines, link previews and AI crawlers. It reads User-Agent Client Hints, so Windows 11, Brave and real Android models show up as they are.

It's 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.

Then ask: $request->device(). Or see what it makes of 34 real visitors in the live demo first.

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.

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.

Features

Requirements

Moving from jenssegers/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:

Configuration

Everything works without configuration. To change the defaults:

Key Default
client_hints.read true (DEVICE_CLIENT_HINTS) Use Sec-CH-UA-* headers when the browser sends them
client_hints.request platform version, model, full version list, form factors What the device.hints middleware asks for
client_hints.critical [] Hints to also send as Critical-CH: the browser retries the first request with them
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()

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:

or per route with ->middleware('device.hints'). 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.

Good to know:

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:

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

Category Who
Search Googlebot, Bingbot, DuckDuckBot, Applebot, YandexBot, Baiduspider, PetalBot...
AiCrawler GPTBot, ClaudeBot, CCBot, Bytespider, Google-Extended, Applebot-Extended, Meta-ExternalAgent, Amazonbot, cohere-ai, Diffbot...
AiSearch OAI-SearchBot, Claude-SearchBot, PerplexityBot, YouBot...
AiAssistant ChatGPT-User, Claude-User, Perplexity-User, MistralAI-User, DuckAssistBot: one page, fetched because a person asked
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 by reverse DNS or the operator's published IP ranges. Google-Extended and Applebot-Extended are robots.txt names; their owners crawl as Googlebot and Applebot, so expect them only from impostors.

Blade

@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).

For developers

PHP API

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
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:

For bots, bot is {"name": "GPTBot", "category": "ai-crawler"}. Device::fromArray() reads it 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

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) and UnknownMethod (a magic method on Agent that doesn't start with "is"; still a BadMethodCallException, as before).

In your tests

Ruvelo\Device\Testing\UserAgents holds real, current User-Agents, so you don't have to collect them:

How detection works

The package keeps its own rule tables, in 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.

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, 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.

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. See 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.


All versions of laravel-device with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
laravel/framework Version ^12.4.1|^13.0
mobiledetect/mobiledetectlib Version ^4.11
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ruvelo/laravel-device contains the following files

Loading the files please wait ...