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

This package is used in Laravel Jetstream.


The most reputable Laravel package provided for detecting user agent is Agent developed by Jens Segers. All the information you need to know about user are accessible by using Agent (jenssegers/agent) package. Agent utilizes the Mobile Detect PHP Class under the hood. Agent makes Laravel equipped to detect the user environment, i.e:

1- Detecting user platform and its version: Including Windows, Ubuntu, OS X, AndroidOS, etc.

2- Detecting user device and device name: Including mobile, tablet, desktop and it will get its name (iPhone, Nexus, AsusTablet, …).

3- Detecting user browser and its version: Including Firefox, Chrome, Safari, IE, etc.

4- And also detecting user language.

How to implement:

First of all do this:

composer require jenssegers/agent

Then find the config/app.php and then find providers key as below:

Then add this line as the Agent service provider to the array of providers:


Then in config/app.php find the aliases key as below:

add an alias for Agent to the array of aliases like:

'Agent' => Jenssegers\Agent\Facades\Agent::class,

It’s done!

How to use:

First, put this line at the top of the controller:

use Jenssegers\Agent\Agent;

Then start by creating an Agent instance (or use the Agent Facade).

$agent = new Agent();

Useful methods:

// Ubuntu, Windows, OS X, ...
// Chrome, IE, Safari, Firefox, ...
$browser = $agent->browser();
$version = $agent->version($browser);
$platform = $agent->platform();
$version = $agent->version($platform);

and more:

$agent->is('OS X');
// ['nl-nl', 'nl', 'en-us', 'en']
// iPhone, Nexus, AsusTablet, ...
// robot name

More examples and original methods can be find here:

Blade view file usage:

If you pass the $agent to a specific view blade file you can do this:

@if ($agent->isMobile())

Show content for mobile ...


Global Blade view file usage:

Moreover you can share $agent and make it available inside all of your view blade files in this way:

Make AgentServiceProvider.php in app/providers/ directory by :

php artisan make:provider AgentServiceProvider

Then register this provider (the below line) in config/app.php file in the array of providers as described before:


Then fill the AgentServiceProvider.php with:

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

Then inside the view blade file use this:

@if ($agent->isMobile())

Show content for mobile ...

Some other useful packages:








Thank you for reading! If you enjoyed this article:

Clap it ! Share it! Follow Me in Medium!

Also I’d like to hear your opinion on this article. If you have any doubt, question or suggestion please leave a comment below.

Have a very wonderful day!

Previous Stories You will Love:

Posting about Python and Laravel

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to push our code in GitHub

Auto Pi Backup to NAS

Why my blog is on Medium

Jupyter Hacks and Tips

Beta of a stock using Python

Travis Continuous deployment for your open source library

The Beginning: From a developer that has been there

Going Serverless (on AWS)

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


Posting about Python and Laravel

More from Medium

Send push notifications using OneSignal with Flutter, Firebase & PHP Laravel.

How to Publish PHP Website (Install CodeCanyon Scripts)

Integrate Twilio, Stripe API and Laravel

firebase and laravel