How to get user device data in Laravel, in clear text format? Find out your user device, OS, browser, browser version, is he coming from desktop or mobile...




Step 1 install Github package
Install https://github.com/jenssegers/agent


Step 2 - add dependencies

Add the service provider in config/app.php:

Jenssegers\Agent\AgentServiceProvider::class,

And add the Agent alias to config/app.php:

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

Step 3 - use it in your controller 

                    use Jenssegers\Agent\Agent;

$agent = new Agent();
                  

Create array of device data:

                    $deviceData = [
    'device' => $agent->device(),
    'OS' => $agent->platform(),
    'browser' => $agent->browser(),
    'browser' => $agent->browser(),
    'browser_version' =>$agent->version($agent->browser()),
    'is_desktop' => $agent->isDesktop(),
    'is_mobile' => $agent->isPhone(),
];
                  

That's it.