How can I pass data from 5 different data from my db using a controller in Laravel 5.4?
I am new to laravel 5.4 and want to sum 5 different data from my db when I view a specific guest with id in the database? I cannot receive the amount or the total amount
Here's my code:
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);
}
+3
source to share
2 answers
The problem is what you are posting forPayment
to your view. But you are not submitting $total_fee
. You need to have a second method with()
or you need to send an array to the method with()
. For example:
return view('cashier-dashboard.paid.show')
->with('forPayment', $forPayment)
->with('totalFee', $total_fee);
Or as an array:
return view('cashier-dashboard.paid.show')
->with(['forPayment' => $forPayment, 'totalFee' => $total_fee]);
In both examples, you can use $totalFee
in your view to get the total.
+2
source to share