What if I want to pass a variable like $k =1 (but the value of $K changes because it's a for loop counter) from view as an argument in a function in the controller without using the URL. The status column is represented in the database table "parcel" from 0-2. For example, in the foreach loop if the value of $k =0 then the controller function gets the value of $k, counts the number of times 0 appears in the database (status) using the count() method, then returns the value of count to the View.
View
@php
$status_arr = array("Item Accepted by Courier","Collected","Shipped");
@endphp
@foreach($status_arr as $k =>$v)
<!-- Parcel stages -->
<div class="col-xl-3 col-md-6 mb-4">
<div class="card border-left-warning shadow h-100 py-2">
<div class="card-body">
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="text-xs font-weight-bold text-warning
text-uppercase mb-1">
{{$v}}
</div>
<div class="h5 mb-0 font-weight-bold text-gray-800">
{{$statuses}}
</div>
</div>
<div class="col-auto">
<i class="fas fa-bicycle fa-2x text-gray-300"></i>
</div>
</div>
</div>
</div>
</div>
@endforeach
Controller
function total_parcels()
{
$status = DB::table('parcels')
->where('status', '=', $k)
->count();
return view('dashboard', ['statuses' => $status]);
}
Route
Route::get('dashboard', [DashboardController::class, 'total_parcels']);