PHP code example of ruvelo / laravel-device

1. Go to this page and download the library: Download ruvelo/laravel-device library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ruvelo / laravel-device example snippets


$device = $request->device();

$device->type;               // DeviceType::Phone
$device->browser->name;      // "Samsung Internet"
$device->os->atLeast(15);    // true
$device->model;              // "SM-S938B"
$device->isAiBot();          // false

// bootstrap/app.php
->withMiddleware(function (Middleware $middleware) {
    $middleware->web(append: \Ruvelo\Device\Http\Middleware\RequestClientHints::class);
})

$device->isBot;          // true
$device->botName;        // "ClaudeBot"
$device->botCategory;    // BotCategory::AiCrawler
$device->isAiBot();      // true for AiCrawler, AiSearch and AiAssistant

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

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();

php artisan vendor:publish --tag=device-config