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,
How to use:
First, put this line at the top of the controller:
Then start by creating an Agent instance (or use the Agent Facade).
$agent = new Agent();
// Ubuntu, Windows, OS X, ...$agent->browser();
// Chrome, IE, Safari, Firefox, ...$browser = $agent->browser();
$version = $agent->version($browser);$platform = $agent->platform();
$version = $agent->version($platform);
// ['nl-nl', 'nl', 'en-us', 'en']$agent->device();
// iPhone, Nexus, AsusTablet, ...$agent->isDesktop();
// 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:
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:
class AgentServiceProvider extends ServiceProvider
public function boot()
$agent = new Agent();
public function register()
Then inside the view blade file use this:
Show content for mobile ...@endif
Some other useful packages:
Thank you for reading! If you enjoyed this article:
Clap it ! Share it! Follow Me in Medium!
Panjeh — Medium
Read writing from Panjeh on Medium. Physicists PhD, Self-taught web developer #Learning, #laravelphp #Vuejs. Every day…
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:
Laravel call named routes in console internally php artisan command
How to call Laravel routes internally php artisan command
Telegram Bot Packages libraries Examples in Laravel, PHP, Node.js, Python, Java, Ruby, Swift, C++
If you want to learn more about Telegram bots, This Introduction to Bots would be a good guide to start.
Laravel Auth::routes() Email verification Reset password Authentication Registration routes
Auth::routes() is a helper class that helps you generate all the routes required for user authentication
Laravel eloquent model increment with or without updating timestamps
Problem: You may need to increment a field in a record of a table (Laravel Model) and do not want update the updated_at…
Laravel validation username no space allowed alpha_dash or regex custom rule
If you want to restrict the username in Laravel to only accept letters, numbers, dashes and underscores and not space…
Laravel delete queued jobs using redis horizon artisan command
The question is how to delete all jobs which are queued in Laravel when you are using redis as the Queue driver.
Laravel define global constants Config php file
If you look at the main Laravel directory you can find these subdirectories:
Laravel session flash message include html tag link href
In Laravel you may insert a or strong tags into the flash message deliver to the session.
Laravel 502 Bad Gateway when starting Laravel Valet — Simple solution
The first solution is here: