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.

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!

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

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

@if ($agent->isMobile())

Show content for mobile ...


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








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!

Posting daily about Python, Nuclear Physicist PhD