In Laravel development, I came across the situation to get the client’s browser or user agent details in server side. Here I am going to share how I have solved it.
Solution:
First we have to import the necessary library. To import library run the following command from the project’s root folder. This will add the library into the composer.json file.
composer require jenssegers/agent
I have used the below function to get the device or user agent details from laravel function.
$device = Agent::device(); // Returns Macintosh, Windows, iPhone, Android etc
or
$agent = new Agent();
$agent->device();
To check the specific User Agent Data, use the below function
$isWindows = $agent->is('Windows');
$isFF = $agent->is('Firefox');
$isIphone = $agent->is('iPhone');
$isOSx = $agent->is('OS X');
To check mobile device:
$isMobile = $agent->isMobile();
$isTablet = $agent->isTablet();
To get the Browser name:
$browser = $agent->browser();
To get Operating System name:
$operating_system_name = $agent->platform();
There are many other functions also available with this library. For more details refer this Github reference.
Happy coding!!!