[英]Laravel Consolestvs\charts - Displaying data belonging to specific user whos logged in, in a chart
我正在使用Laravels Consoletvs \\ charts為我的項目生成圖表。 我正在嘗試讓圖表僅顯示特定用戶創建的“問題”,當前它僅顯示數據庫中的所有“問題”,但是我不確定如何為此編寫字符串,基本上,我只需要它顯示與當前登錄用戶的ID匹配的“問題”。
任何幫助深表感謝 :)
我的圖表控制器如下所示
$questions = Question::where(DB::raw("(DATE_FORMAT(created_at,'%Y'))"),date('Y'))
->get();
$questionChart = Charts::database($questions, 'bar', 'highcharts')
->title("Questions Assigned")
->elementLabel("Total Questions")
->dimensions(1000, 500)
->responsive(true)
->groupByMonth(date('Y'), true);
return view('welcome', compact('userChart', 'testChart', 'questionChart'));
}
}
如果我沒看錯,那么您想顯示由登錄用戶創建的問題 。
要獲得解決方案,您必須在問題和用戶表之間預先定義一個關系。
我假設您的問題模型中有一個user_id列
$ loggedin_user_id ='some_id';
嘗試這個
$questions = Question::where('user_id', $loggedin_user_id)
->get();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.