Hello Devloper,
In this post we will get User IP all user ajent(computer, mobile and browsers) information using lravel package. In the present age, it is compulsory for every website to get user ajent information.
Mobile_Detect or Computer_Detect is a lightweight package is able to identify the visitors browser and compter or mobile deveices almost perfectly by useing multiple well tested packages and services together Ajent.
User Agent is a PHP Computer/mobile user agent parser with support for Laravel 4,5,6,7 or 8 version, based on Mobile or Computer deveices. It provides both Computer support and additional functionality. This Laravel package utilizes Mobile Detect PHP Class.
In this example i give you step by step get information of User Ajent.
Step 1:Installation
will to install package, you can open a terminal and type the following command
composer require jenssegers/agent
Step 2:Laravel Setting
You go to this path config/app.php
Then add the service provider and aliases below line.
'providers' => [
------
------
Jenssegers\Agent\AgentServiceProvider::class,
],
'aliases' => [
------
------
'Agent' => Jenssegers\Agent\Facades\Agent::class,
]
Step 3: Basic Usage
Start by creating an Agent instance or use the Agent Facade and create a new controller like ProfileController and add below code
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Jenssegers\Agent\Agent;
class ProfileController extends Controllers
{
public function getUserInfo()
{
$agent = new Agent();
$agent->platform(); // Ubuntu, Windows, OS X, ...
$agent->browser(); // Chrome, IE, Safari, Firefox, ...
$browser = $agent->browser();
$version = $agent->version($browser);
$platform = $agent->platform();
$version = $agent->version($platform);
$agent->is('Windows');
$agent->is('Firefox');
$agent->is('iPhone');
$agent->is('OS X');
$agent->isAndroidOS();
$agent->isNexus();
$agent->isSafari();
$agent->languages(); // ['nl-nl', 'nl', 'en-us', 'en']
$agent->device(); // iPhone, Nexus, AsusTablet, ...
$agent->isDesktop();
$agent->isPhone();
$agent->isMobile();
$agent->isTablet();
$agent->isRobot();
$agent->robot(); // robot name
}
}
Step 3: Usage for view blade file
@if((new \Jenssegers\Agent\Agent())->isMobile())
<link rel="stylesheet" href="{{ asset('theme/css/mobile.css') }}" />
@endif
@if((new \Jenssegers\Agent\Agent())->isDesktop())
<link rel="stylesheet" href="{{ asset('theme/css/desktop.css') }}" />
@endif
I hope you found user info and this tutorial help for you.
Related Post