关于 Browser-detect 4.0 的使用方法

最近需要用到一个能够判断当前设备类型的库,于是发现了 Browser-datect 这个神器。看了看官方文档写的非常清楚,打算尝试一下。

由于 Browser-datect 4.0 仅支持 Laravel 6.0 以上版本,所以还特意升级了我的 5.8 版本。然鹅…………接下来我有点懵逼了,文档中提到的那些方法我都调不到,不知道自己在哪里出了错,以下是我的使用方式:

namespace App\Http\Controllers;

use DeviceDetector\Parser\Client\Browser;

class ChatController extends Controller
{
    public function index()
    {
        $mobile = Browser::isMobile();    //这里会报错,isMobile()方法并不存在
        dd($mobile);
    }
}

Laravel 版本:6.5.1
Browser-detect 版本:4.0

代码是写给人看的,顺便给机器运行一下。
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
leo
最佳答案

https://packagist.org/packages/hisorange/b...

use Browser;

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

示例代码已经写得够清楚的了

4年前 评论
luci (楼主) 4年前
讨论数量: 1
leo

https://packagist.org/packages/hisorange/b...

use Browser;

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

示例代码已经写得够清楚的了

4年前 评论
luci (楼主) 4年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!