PHPackages                             tesis/laravel-parse-user-agent - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tesis/laravel-parse-user-agent

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tesis/laravel-parse-user-agent
==============================

Get OS, device, browser from user\_agent

02PHP

Since Sep 16Pushed 1y ago1 watchersCompare

[ Source](https://github.com/tesis/laravel-parse-user-agent)[ Packagist](https://packagist.org/packages/tesis/laravel-parse-user-agent)[ RSS](/packages/tesis-laravel-parse-user-agent/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

LaravelUserAgentParser
======================

[](#laraveluseragentparser)

A Laravel package for parsing user-agent strings to identify device type, operating system, and browser details.

Features
--------

[](#features)

- Identifies operating system (OS) from the user-agent string.
- Identifies the browser and its version.
- Determines the device type (Desktop, Mobile, Tablet).

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require tesis/laravel-user-agent-parser
```

Configuration
-------------

[](#configuration)

If you're using Laravel 5.5 or later, the service provider will automatically be registered. For earlier versions, you'll need to add the service provider manually.

Add the service provider to the `providers` array in `config/app.php`:

```
'providers' => [
    // Other service providers...
    Tesis\LaravelUserAgentParser\Providers\UserAgentParserServiceProvider::class,
],
```

Usage
-----

[](#usage)

### Parsing User-Agent Strings

[](#parsing-user-agent-strings)

You can use the `LaravelUserAgentParser` service to parse a user-agent string and get details about the device, OS, and browser.

### Handling Requests in a Controller

[](#handling-requests-in-a-controller)

You can integrate the parser directly into your Laravel controllers to handle HTTP requests:

```
use Illuminate\Http\Request;
use Tesis\LaravelUserAgentParser\Services\UserAgentParser;

class UserAgentController extends Controller
{
    protected UserAgentParser $userAgentParser;

    public function __construct(UserAgentParser $userAgentParser)
    {
        $this->userAgentParser = $userAgentParser;
    }

    public function index()
    {
        $userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3';
        $parsedData = $this->userAgentParser->parse($userAgent);

        return response()->json($parsedData);
    }
}
```

### Testing

[](#testing)

To ensure everything is working correctly, you can run the package's tests using PHPUnit.

First install Orchestra

```
composer require --dev orchestra/testbench:"^7.0" --with-all-dependencies
```

then install phpunit on top of it (later version seems not to be working):

```
composer require --dev phpunit/phpunit
```

```
vendor/bin/phpunit
```

As we are building a Laravel package, the first thing we will need is Laravels Support package, so install that using the following composer command:

```
composer require illuminate/support
```

> Note: only add it after installing orchestra and phpunit with particular version, otherwise it will be the last version and orchestra and phpunit might have conflicts.

and then in tests you can use it:

```
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
    //
}
```

### Feature Tests

[](#feature-tests)

If your package includes HTTP endpoints, you can test them using feature tests.

```
public function testUserAgentParsingEndpoint()
{
    $userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3';

    $response = $this->postJson('/parse-user-agent', [
        'user_agent' => $userAgent,
    ]);

    $response->assertStatus(200)
             ->assertJson([
                 'device_type' => 'Desktop',
                 'os' => 'Windows',
                 'browser' => 'Chrome',
                 'browser_version' => '58.0.3029.110',
             ]);
}
```

### Static analysis with PHPStan

[](#static-analysis-with-phpstan)

```
composer require --dev phpstan/phpstan
```

Add phpstan.neon:

```
parameters:
    level: 9

    paths:
        - src
```

and run:

```
./vendor/bin/phpstan analyse
```

Contributing
------------

[](#contributing)

Contributions are welcome! Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

If you discover a security vulnerability within this package, please send an email to [your-email@example.com](mailto:tereza@tesispro.eu). All security vulnerabilities will be promptly addressed.

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity17

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/548acde2f88a80e185f45c18c1213bd2725d45e76b6168ca2019dcd45b1e6147?d=identicon)[tesis](/maintainers/tesis)

---

Top Contributors

[![terezasimcic](https://avatars.githubusercontent.com/u/164891336?v=4)](https://github.com/terezasimcic "terezasimcic (2 commits)")

### Embed Badge

![Health badge](/badges/tesis-laravel-parse-user-agent/health.svg)

```
[![Health](https://phpackages.com/badges/tesis-laravel-parse-user-agent/health.svg)](https://phpackages.com/packages/tesis-laravel-parse-user-agent)
```

###  Alternatives

[daverandom/exceptional-json

JSON encoding and decoding that throws exceptions on failure

321.4M9](/packages/daverandom-exceptional-json)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
