gpt4 book ai didi

php - 在 Controller 上使用时未找到类 'App\Http\Controllers\Analytics'

转载 作者:行者123 更新时间:2023-12-01 18:38:59 24 4
gpt4 key购买 nike

我正在使用 spatie/laravel-analytics,当我在 Route.php 上使用它时,一切都工作正常,但是当我尝试在 Controller 中使用它时,它会抛出此错误!有点奇怪!这是我的 Controller 代码:

<?php

namespace App\Http\Controllers;

use Spatie\Analytics\Period;
use Illuminate\Http\Request;
use App\Question;
use App\Contact;
use Carbon\Carbon;


class DashboardController extends Controller
{
public function index()
{

// $questions = Question::whereNull('answer')->get();
// $messages = Contact::where('status', false)->get();


//Data from Google Analytics
$totalVisitors = Analytics::fetchTotalVisitorsAndPageViews(Period::days(7));
// $mostVisitedPages = Analytics::fetchMostVisitedPages(Period::days(7), $maxResults = 5);
// $topReferrers = Analytics::fetchTopReferrers(Period::days(7), $maxResults = 5);
// $topBrowsers = Analytics::fetchTopBrowsers(Period::days(7), $maxResults = 5);

return $totalVisitors;

return view('admin.admin-dashboard', compact(
'messages', 'questions', 'totalVisitors', 'mostVisitedPages', 'topReferrers', 'topBrowsers'
));
}
}

我的route.php代码是:

use Spatie\Analytics\Period;

Route::get('/test', function() {


// Data from Google Analytics
$totalVisitors = Analytics::fetchTotalVisitorsAndPageViews(Period::days(7));
$mostVisitedPages = Analytics::fetchMostVisitedPages(Period::days(7), $maxResults = 5);
$topReferrers = Analytics::fetchTopReferrers(Period::days(7), $maxResults = 5);
$topBrowsers = Analytics::fetchTopBrowsers(Period::days(7), $maxResults = 5);

return $totalVisitors;


});

=

最佳答案

在 Controller 上,您可以在命名空间行之后尝试此操作:

use Analytics; 

关于php - 在 Controller 上使用时未找到类 'App\Http\Controllers\Analytics',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44226585/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com