browser-detect

composer require hisorange/browser-detect

Yep, that's it! At least for lavarel 5.5 and above, for 5.4 and below please read the extended installation.

How to use


In your classes and controllers just call the Browser facade:

// Determine the user's device type is simple as this:
Browser::isMobile();
Browser::isTablet();
Browser::isDesktop();

// Every wondered if it is a bot who loading your page?
if (Browser::isBot()) {
    echo 'No need to wonder anymore!';
}

// Check for vendors.
if (Browser::isFirefox() || Browser::isOpera()) {
    $output .= '<script src="firefox-fix.js"></script>';
}

Even in your blade templates:

{{-- Directives are built in laravel 5.5 and above! --}}
@mobile
    <p>This is the MOBILE template!</p>
    @include('your-mobile-template')
@endmobile

@tablet
    <p>This is the TABLET template!</p>
    <link rel="stylesheet" href="tablet.css" title="Reduce the page size, load what the user need">
@endtablet

@desktop
    <p>This is the DESKTOP template!</p>
@enddesktop

// Every key is supported.
@browser('isBot')
    <p>Bots are identified too :)</p>
@endbrowser

Available API calls


Every call on the Browser facade is mirrored to the result object, so the following informations are available on your result too, where you can use the array syntax to access them.

CallResponseInternal Type
Browser::userAgent()Current visitor's HTTP_USER_AGENT string.(string)
Browser::isMobile()Is this a mobile device.(boolean)
Browser::isTablet()Is this a tablet device.(boolean)
Browser::isDesktop()Is this a desktop computer.(boolean)
Browser::isBot()Is this a crawler / bot.(boolean)
Browser related functions  
Browser::browserName()Browser's human friendly name like Firefox 3.6, Chrome 42.(string)
Browser::browserFamily()Browser's vendor like Chrome, Firefox, Opera.(string)
Browser::browserVersion()Browser's human friendly version string.(string)
Browser::browserVersionMajor()Browser's semantic major version.(integer)
Browser::browserVersionMinor()Browser's semantic minor version.(integer)
Browser::browserVersionPatch()Browser's semantic patch version.(integer)
Browser::browserEngine()Browser's engine like: Blink, WebKit, Gecko.(string)
Operating system related functions  
Browser::platformName()Operating system's human friendly name like Windows XP, MacOS 10.(string)
Browser::platformFamily()Operating system's vendor like Linux, Windows, MacOS.(string)
Browser::platformVersion()Operating system's human friendly version like XP, Vista, 10.(integer)
Browser::platformVersionMajor()Operating system's semantic major version.(integer)
Browser::platformVersionMinor()Operating system's semantic minor version.(integer)
Browser::platformVersionPatch()Operating system's semantic patch version.(integer)
Device related functions  
Browser::deviceFamily()Device's vendor like Samsung, Apple, Huawei.(string)
Browser::deviceModel()Device's brand name like iPad, iPhone, Nexus.(string)
Browser::mobileGrade()Device's mobile grade in scale of A,B,C for performance.(string)
Browser vendor related functions  
Browser::isChrome()Is this a chrome browser.(boolean)
Browser::isFirefox()Is this a firefox browser.(boolean)
Browser::isOpera()Is this an opera browser.(boolean)
Browser::isSafari()Is this a safari browser.(boolean)
Browser::isIE()Checks if the browser is an some kind of Internet Explorer (or Trident)(boolean)
Browser::isIEVersion()Compares to a given IE version(boolean)

Version support


The following matrix is being continuously tested by the great and awesome Travis CI!

-----PHP 5.6PHP 7.0PHP 7.1PHP 7.2
Laravel 5.0---
Laravel 5.1---
Laravel 5.2---
Laravel 5.3---
Laravel 5.4
Laravel 5.5-

* Cannot auto test the laravel 5.4 on PHP 7.1 because of version incompatibility between the PHPUnit, Laravel and the package testing library, but the versions are tested manually.

Laravel 4.x support

Laravel 4.x releases are not actively developed but you can still use the browser detect 1.x for it; You can find those releases under the versions tab. Please read the readme from the release use choose, after version 2.x the package was redesigned from the sketch so nor the installation nor the usage is the same.

Extended Installation


If you are using laravel 5.4 and below you have to add the service provider in your config/app.php like this:

    'providers' => [
        // Package Service Providers...
        \hisorange\BrowserDetect\ServiceProvider::class,
    ]

and don't forget to add the facade in the same file like this:

    'aliases' => [
        'Browser' => \hisorange\BrowserDetect\Facade::class,
    ]

Extended Usage Information


The code is designed to be an easy to use style, so every call you make on the Browser facade will access the result object and get the data for you, but you can parse agents other then the current user's.

// When you call the detect function you will get a result object, from the current user's agent.
$result = Browser::detect();

// If you wana get browser details from a user agent other then the current user call the parse function.
$result = Browser::parse('Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14');
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值