我是laravel 5.4的新手,当我在数据库中查看具有id的特定guest虚拟机时,我想从我的db中总计5个不同的数据?我无法得到总和或总数
这是我的代码:
public function show($id)
{
$forPayment = ForPayment::where('application_number', $id)->get()->last();
if (empty($forPayment)) {
Flash::error('For Payment not found');
return redirect(route('forPayments.index'));
}
$inspection_fee = $forPayment->inspection_fee;
$storage_fee = $forPayment->storage_fee;
$cert_fee = $forPayment->cert_fee;
$local_fee = $forPayment->local_fee;
$others_fee = $forPayment->others_fee;
$total_fee = $inspection_fee + $storage_fee + $cert_fee + $local_fee + $others_fee;
return view('cashier-dashboard.paid.show')->with('forPayment', $forPayment, $total_fee);
}
答案 0 :(得分:2)
return view('cashier-dashboard.paid.show',compact('forPayment','total_fee'));
试试这个
答案 1 :(得分:2)
问题是您将forPayment
发送到您的视图。但是你没有发送$total_fee
。您需要使用第二个with()
方法,或者需要将数组发送到with()
方法。例如:
return view('cashier-dashboard.paid.show')
->with('forPayment', $forPayment)
->with('totalFee', $total_fee);
或作为数组:
return view('cashier-dashboard.paid.show')
->with(['forPayment' => $forPayment, 'totalFee' => $total_fee]);
通过这两个示例,您可以在视图中使用$totalFee
来获取总费用。