我想将变量数据发送到视图但是我收到错误:
未定义的变量:总计 下面是控制器的代码:
public function show(Qualificationheader $qualificationheader)
{
$qualificationheader = Qualificationheader::findOrFail($qualificationheader->id);
$data = Information::where('curriculum_id','=',1)->first();
$total = Information::where('curriculum_id','=',1)->sum('km_credits');
// dd($total);
return view('qualificationheaders.show', ['qualificationheader'=>$qualificationheader], ['information'=>$data],['total'=>$total]);
}
我的印象是:
return view('qualificationheaders.show', ['qualificationheader'=>$qualificationheader], ['information'=>$data],['total'=>$total]);
足以将计算值发送到视图
在视图中:{{$total}}
我可能做错了什么?当我总计dd时,我得到正确的值。
答案 0 :(得分:1)
您只需将一个数组传递给view
帮助程序:
return view('qualificationheaders.show', compact('qualificationheader', 'data', 'total'));
或者如果您需要使用特定的变量名称:
return view('qualificationheaders.show', [
'qualificationheader' => $qualificationheader,
'information' => $data,
'total' => $total
]);