In this post, i will show you, How we can get user Devices like Desktops, Mobile, Tablets, browsers like Chrome, Firefox, etc, and OS like Linux, OS X, and Windows.
This will be required, we are creating a Project which you have to make according to Device or Browser, or OS platform
Step 1. Install Laravel
Step 2. Install Package (jenssegers/Agent)
Step 3. Create controller and Route
Step 4. Output
Step 5. Conclusion
Step 1. Install Laravel
As you are looking this example, so definitely you already installed the laravel app, But still i am showing you how we can install.
composer create-project laravel/laravel PlatformFinder
Step 2. Install Package (jenssegers/Agent)
Now we will use jenssegers/agent package which will help us to Find all the details. Now use the below command to install this package.
composer require jenssegers/agent
Step 3. Create controller and Route
Now create a controller using the artisan command.
php artisan make:controller DeviceController
Now create the functions like below.
<?php namespace App\Http\Controllers; use Jenssegers\Agent\Facades\Agent; use Illuminate\Http\Request; class DeviceController extends Controller { public function index() { $device = Agent::device(); echo $device; $platform = Agent::platform(); echo "<br>"; echo $platform; $version = Agent::version($platform); echo "<br>"; echo $version; echo "<br>"; $browser = Agent::browser(); echo $browser; echo "<br>"; $browser_version = Agent::version($browser); echo $browser_version; } }
Note- don’t forgot to import the package.
use Jenssegers\Agent\Facades\Agent;
Now open routes/web.php
use App\Http\Controllers\DeviceController; Route::get("/device",[DeviceController::class,'index']);
Now this step done.
Step 4. Output
it’s simple just open run your project using artisan command and open the provide url
http://127.0.0.1:8000/device
Step 5. Conclusion
Hopefully , this example will gives you some idea about, how we can use the use the client details. And if you are building a high scale web app, i am sure this will help you.
If you feel it’s helpful for you then, Like and share.