douben7493 2016-07-12 16:27
浏览 124
已采纳

如何使用Laravels spatie / laravel分析包

I just downloaded this package for Laravel.

spatie/laravel-analytics

Its a Google Anayltics package, and I followed all the steps for setting up an account. What I'm having trouble is calling the methods. For example when it says:

Here is an example to retrieve visitors and pageview data for the current day and the last seven days.

$analyticsData = Analytics::fetchVisitorsAndPageViews(Period::days(7));

I tried doing this in my function like this:

<?php

namespace App\Http\Controllers\Admin;

use Carbon\Carbon;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Spatie\Analytics\Analytics;
use Illuminate\Support\Collection;

class DashboardController extends Controller {


        public function index() { 

            $analytics = Analytics::fetchVisitorsAndPageViews(Period::days(7));  
            dd($analytics);

            return view('admin.dashboard-v2');
        }

}

Its giving me errors like:

Non-static method Spatie\Analytics\Analytics::fetchVisitorsAndPageViews() should not be called statically

Am I missing something here? I couldn't find any specific documentation online except for the Github ReadMe file

  • 写回答

1条回答 默认 最新

  • douyao3895 2016-07-13 09:09
    关注

    If you want to use the facade to access the class, you'll need to change use Spatie\Analytics\Analytics; to use Analytics;. That should take care of that error.

    If you are going to use Period::days(7) then you will need to add use Spatie\Analytics\Period; because that's an actual static method, not a facade.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 mmseqs内存报错
  • ¥15 vika文档如何与obsidian同步
  • ¥15 华为手机相册里面的照片能够替换成自己想要的照片吗?
  • ¥15 陆空双模式无人机飞控设置
  • ¥15 sentaurus lithography
  • ¥100 求抖音ck号 或者提ck教程
  • ¥15 关于#linux#的问题:子进程1等待子进程A、B退出后退出(语言-c语言)
  • ¥20 web页面如何打开Outlook 365的全球离线通讯簿功能
  • ¥15 io.jsonwebtoken.security.Keys
  • ¥15 急,ubuntu安装后no caching mode page found等