我在將多個變量從控制器傳遞到視圖/刀片時出現問題。即時通訊使用compact()
來傳遞變量,但我認爲我已經達到了傳遞變量的限制因爲我已經測試了我的代碼,它會在傳遞30個變量後停止工作。並會給出一個錯誤:「未定義的變量:」,儘管它已經被定義並且完全不運行,除非我傳遞了超過30個變量。我需要傳遞許多變量bcoz我正在創建圖表,並且圖表中的每個值(x,y軸)都是不同的變量。有沒有其他方法可以做到這一點?我正在考慮爲單個視圖使用多個控制器。可能嗎? 總之,這裏是從我的控制器的一個片段:Laravel - 將太多變量傳遞給視圖
$ic15 = SchoolStats::where('school_id', $id)->groupBy('college_id')->where('college_id', 0)->where('year_admitted', 2015)->count();
$cas15 = SchoolStats::where('school_id', $id)->groupBy('college_id')->where('college_id', 1)->where('year_admitted', 2015)->count();
$ce15 = SchoolStats::where('school_id', $id)->groupBy('college_id')->where('college_id', 2)->where('year_admitted', 2015)->count();
$uep15 = SchoolStats::where('school_id', $id)->groupBy('college_id')->where('college_id', 3)->where('year_admitted', 2015)->count();
$ced15 = SchoolStats::where('school_id', $id)->groupBy('college_id')->where('college_id', 4)->where('year_admitted', 2015)->count();
$cet15 = SchoolStats::where('school_id', $id)->groupBy('college_id')->where('college_id', 5)->where('year_admitted', 2015)->count();
$saec15 = SchoolStats::where('school_id', $id)->groupBy('college_id')->where('college_id', 6)->where('year_admitted', 2015)->count();
$cgb15 = SchoolStats::where('school_id', $id)->groupBy('college_id')->where('college_id', 7)->where('year_admitted', 2015)->count();
return view('success', compact('col','school', 'total', 'f', 'm', 'ic', 'cas', 'ce', 'uep', 'ced', 'cet', 'saec', 'cgb', 'icf', 'icm', 'casf', 'casm', 'cef', 'cem', 'uepf', 'uepm', 'cedf', 'cedm', 'cetf', 'cetm', 'saecf', 'saecm', 'cgbf', 'cgbm', 'ic13', 'cas13', 'ce13', 'uep13', 'ced13', 'cet13', 'saec13', 'cgb13', 'ic14', 'cas14', 'ce14', 'uep14', 'ced14', 'cet14', 'saec14', 'cgb14', 'ic15', 'cas15', 'ce15', 'uep15', 'ced15', 'cet15', 'saec15', 'cgb15'));
這只是一個片段,其他變量$ic15
之前已經被定義。它的定義和使用就像上面顯示的從$ic15
到$cgb15
的其他變量一樣。
它解決您的問題,您return語句? –
感謝您的快速解答,先生agam。我必須先嚐試一下你的方法......但是看起來你的代碼正在工作,因爲有人提高了你的答案。我將在後面標記爲答案,如果它能解決我的問題:)) – jeanawhou
當然。希望它適合你 –