I am trying to create a menu with food and price ,when I Choose the food that I want ( using checkbox ) I want to receive also the price of that specific choosen food.
PS: I am using laravel 7 (without jquery), I can receive the food after checking it but not its price. So My question how to select the whole row with one checkbox.enter image description here
view:
<form action="" method="post">
@csrf
@method('post')
<input type="hidden" name="restaurantname" value="Restaurant A">
<div class="form-group">
<div class="card-header">
<div class="row">
<div class="form-group col-md-4">
</div>
<div class="form-group col-md-4">
</div>
<div class="form-group col-md-4">
</div>
</div>
</div>
<div id="row-1">
<div class="row">
<div class="form-group col-md-4">
<input type="checkbox" name="salade[]" value="salade1" id="chk-1" />Salade1
</div>
<div class="form-group col-md-4">
<input type="checkbox" value="30" id="price" name="price[]"> 30 Dh
</div>
<div class="form-group col-md-4">
<input type="checkbox" value="1" name="qt[]"> 1
<input type="checkbox" value="2" name="qt[]"> 2
<input type="checkbox" value="3" name="qt[]"> 3
<input type="checkbox" value="4" name="qt[]"> 4
</div>
</div>
</div>
<br>
<div id="row-2">
<div class="row">
<div class="form-group col-md-4">
<input type="checkbox" name="salade[]" value="salade2" />Salade2
</div>
<div class="form-group col-md-4">
<input type="checkbox" value="40" id="price2" name="price[]"> 40 Dh
</div>
<div class="form-group col-md-4">
<input type="checkbox" value="1" name="qt[]"> 1
<input type="checkbox" value="2" name="qt[]"> 2
<input type="checkbox" value="3" name="qt[]"> 3
<input type="checkbox" value="4" name="qt[]"> 4
</div>
</div>
</div>
</div>
controller : I just wanna see them , not inserting them in DB, not yet
public function add(Request $request)
{
echo ($request->restaurantname);
$checked_array= $request->salade;
if ($checked_array) {
foreach ($checked_array as $c) {
echo ($c);
}
}
}
Aucun commentaire:
Enregistrer un commentaire