[英]Using the Google Analytics PHP Client Library in Laravel
I am fairly new to Laravel and am trying to integrate the Google Analytics PHP Client Library ( https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/service-php ) in an application I am building. 我对Laravel并不陌生,并且正在尝试将Google Analytics(分析)PHP客户端库( https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/service-php )集成到我正在构建的应用程序中。
According to the documentation , the library needs to be installed via Composer and then loaded using: 根据文档,需要通过Composer安装该库,然后使用以下方法加载该库:
require_once __DIR__ . '/vendor/autoload.php';
In the vendors folder, I can see that there is a folder named google. 在vendor文件夹中,我可以看到有一个名为google的文件夹。 So my question is, what would be the correct way to load this library in Laravel?
所以我的问题是,在Laravel中加载该库的正确方法是什么? Would it be using the code shown above, or some other method?
它会使用上面显示的代码还是其他方法?
Thanks 谢谢
The autoload.php file is already required by your laravel app, you should be able to access it by it's namespace after running composer dump-autoload
as suggested by Ayaz. 您的laravel应用程序已经需要autoload.php文件,按照Ayaz的建议运行
composer dump-autoload
后,您应该能够通过其名称空间访问它。
You may want to look at a package like https://github.com/spatie/laravel-analytics where they've done the work to integrate the google analytics api into Laravel a bit more. 您可能想看看像https://github.com/spatie/laravel-analytics这样的软件包,他们在其中完成了将Google Analytics(分析)API集成到Laravel中的工作。 Even if you don't use it I'm sure you can glean some good info from checking out the source files.
即使您不使用它,我也可以从签出源文件中收集一些好的信息。
According to the documentation , the library needs to be installed via Composer and then loaded
根据文档,需要通过Composer安装该库,然后进行加载
You can do it by executing following command in your git bash or cmd 您可以通过在git bash或cmd中执行以下命令来完成此操作
$ composer dump-autoload
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.