PHP Laravel : How to get client browser/ Device?

后端 未结 5 667
野趣味
野趣味 2021-01-18 05:22

I\'m building a laravel application where I want to keep track of client browser details such as browser name. How do I do it using Laravel ?

public function         


        
5条回答
  •  醉酒成梦
    2021-01-18 05:40

    First add the package to your composer:

    {
        "require": {
            "hisorange/browser-detect": "2.*" // For laravel 5.* versions
            "hisorange/browser-detect": "1.*" // For laravel 4.* versions
        }
    }
    

    After the composer update/install add the service provider to your app.php:

    'providers' => array(
        // ...
        'hisorange\BrowserDetect\Provider\BrowserDetectService',
        // ...
    )
    

    Add the alias to the aliases in your app.php:

    'aliases' => array(
        // ...
        'BrowserDetect' => 'hisorange\BrowserDetect\Facade\Parser',
    )
    

    You must use personal configurations, just publish the package's configuration files, (plugins.php also published with this)

    php artisan vendor:publish
    

    You can get result informations by simply call on the facade.

    // You can always get the result object from the facade if you wish to operate with it.
    BrowserDetect::detect(); // Will resolve and return with the 'browser.result' container.
    
    // Calls are mirrored to the result object for easier use.
    BrowserDetect::browserVersion(); // return '3.6' string.
    
    // Supporting human readable formats.
    BrowserDetect::browserName(); // return 'Firefox 3.6' string.
    
    // Or can be objective.
    BrowserDetect::browserFamily(); // return 'Firefox' string.
    

    For details: https://github.com/hisorange/browser-detect

提交回复
热议问题