我正在学习k1,但是总是有一个问题,我已经定义了值laravel,但是还有很多未定义的问题
这是我的控制器
class DozentController extends Controller
{
// sql query from datebase
public function number()
{
$questions = DB::table('questions')->count('id');
$kapitel1 = DB::table('questions')->where('chapters_id','1')->count('id');
$kapitel2 = DB::table('questions')->where('chapters_id','2')->count('id');
$kapitel3 = DB::table('questions')->where('chapters_id','3')->count('id');
$kapitel4 = DB::table('questions')->where('chapters_id','4')->count('id');
$kapitel5 = DB::table('questions')->where('chapters_id','5')->count('id');
$kapitel6 = DB::table('questions')->where('chapters_id','6')->count('id');
$kapitel7 = DB::table('questions')->where('chapters_id','7')->count('id');
$kapitel8 = DB::table('questions')->where('chapters_id','8')->count('id');
$kapitel9 = DB::table('questions')->where('chapters_id','9')->count('id');
return view('/statisticsA',['question' => $questions , 'group' => $groups , 'k1' => $kapitel1 ,
'k2' => $kapitel2 , 'k3' => $kapitel3 , 'k4' => $kapitel4 , 'k5' => $kapitel5 ,
'k6' => $kapitel6 , 'k7' => $kapitel7 , 'k8' => $kapitel8 , 'k9' => $kapitel9]);
}
}这是我的路线
Route::get('/statisticsA', 'DozentController@number');
Route::get('/statisticsA', [
'uses' => 'PagesController@getStatisticsAdmin',
'as' => 'statisticsA',
'middleware' => 'roles',
'roles' => ['Author','Admin']
])->middleware('auth');还有我的刀锋
<div>Die Anzahl von Fragen für Kapitel 1</div>
<p> {{ $k1 }} </p>发布于 2021-07-01 21:16:44
只需一个查询即可逃脱惩罚
$questions = DB::table('questions')->selectRaw('COUNT(chapters_id) AS total, chapters_id')->groupBy('chapters_id', 'asc');SQL将为:
SELECT chapters_id, COUNT(chapters_id) as total FROM questions GROUP BY chapters_id;这将为您提供按章计数。
同样,在您的情况下,第二个路由将不起作用。因为Laravel在解析时永远看不到这个路由,所以你的PagesController@getStatisticsAdmin永远不会捕捉到结果。
Route::get('/statisticsA', [
'uses' => 'PagesController@getStatisticsAdmin',
'as' => 'statisticsA',
'middleware' => 'roles',
'roles' => ['Author','Admin']
])->middleware('auth');https://stackoverflow.com/questions/68209894
复制相似问题