A package that can detect mobile or desktop user in Laravel
Still troubled with how to detect mobile device or desktop device?
Sometimes we might think about how do we control our web view in mobile or tablet. Today I gonna should you a package that can let us easy to manage it, it will help us more it our development if you are doing desktop and mobile view.
This package can install it via composer with a simple command:
composer require jenssegers/agent
After the installation you might have an option in Laravel which you can add the service provider in your config or not. If yes, please follow the following below:
Add the Service Provider in
And add the Agent Alias to
'Agent' => Jenssegers\Agent\Facades\Agent::class,
Let start with the basic, when we want to use the agent, we must include the provider:
$agent = new Agent();
There was a few function we may use it in our development which is
The example above is to check are your currently browser platform or device.
There have another way which is the example below is also a easy way to detect the mobile device which are using IOS or Android.
Next, check for mobile device or desktop device:
$agent->isPhone(); // this is to…