Laravel detector mobile browser name version platform device robot crawler user language

Image for post
Image for post

Introduction:

How to implement:

composer require jenssegers/agent
Image for post
Image for post
Jenssegers\Agent\AgentServiceProvider::class,
Image for post
Image for post
'Agent' => Jenssegers\Agent\Facades\Agent::class,

How to use:

use Jenssegers\Agent\Agent;
$agent = new Agent();

Useful methods:

$agent->platform();
// Ubuntu, Windows, OS X, ...
$agent->browser();
// Chrome, IE, Safari, Firefox, ...
$browser = $agent->browser();
$version = $agent->version($browser);
$platform = $agent->platform();
$version = $agent->version($platform);
$agent->is('Windows');
$agent->is('Firefox');
$agent->is('iPhone');
$agent->is('OS X');
$agent->isAndroidOS();
$agent->isNexus();
$agent->isSafari();
$agent->languages();
// ['nl-nl', 'nl', 'en-us', 'en']
$agent->device();
// iPhone, Nexus, AsusTablet, ...
$agent->isDesktop();
$agent->isPhone();
$agent->isMobile();
$agent->isTablet();
$agent->isRobot();$agent->robot();
// robot name

Blade view file usage:

@if ($agent->isMobile())

Show content for mobile ...

@endif

Global Blade view file usage:

php artisan make:provider AgentServiceProvider
App\Providers\AgentServiceProvider::class,
namespace App\Providers;

use View;
use Jenssegers\Agent\Agent;
use Illuminate\Support\ServiceProvider;

class AgentServiceProvider extends ServiceProvider
{
public function boot()
{
$agent = new Agent();

View::share('agent', $agent);
}

public function register()
{
//
}
}
@if ($agent->isMobile())

Show content for mobile ...
@endif

Some other useful packages:

Previous Stories You will Love:

Written by

Web geek, Self-taught full-stack web developer, Learning Python, Laravel, Vuejs, UX/UI design, Nuclear Physicist PhD

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store