How to Get User Agent Value in Laravel?

By Hardik Savani April 16, 2024 Category : Laravel

Hey Artisan,

This extensive guide will teach you how to get user agent in laravel. step by step explain laravel 10 get user-agent. you will learn laravel user agent package. you will learn laravel get user agent from request. So, let's follow a few steps to create an example of laravel detect user agent.

You can use this example with laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11.

In Laravel, you can easily retrieve the user agent value of a client's browser by using the built-in Request class. Here's an example of how to get the user agent value in Laravel:

Example 1:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\RedirectResponse;

use Illuminate\Http\Request;

class UserController extends Controller

{

/**

* Store a new user.

*/

public function store(Request $request): RedirectResponse

{

$userAgent = $request->server('HTTP_USER_AGENT');

dd($userAgent);

}

}

Example 2:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\RedirectResponse;

use Illuminate\Http\Request;

class UserController extends Controller

{

/**

* Store a new user.

*/

public function store(Request $request): RedirectResponse

{

$userAgent = $request->header('User-Agent');

dd($userAgent);

}

}

I hope it can help you...

Tags :
Shares