i was trying to pass an input to a function which is update in this case.The thing is that whenever I submit the form I don't receive this specific input so I tried many stuff one of them is that I have created a test input and I was able to receive it correctly in $request
.
also tried changing its name to say quantity for this example but it didn't work.
please check my code and tell me if I am missing something.Thanks alot.
front-end
<form action="/shopping-cart/update/{{$product->item_id}}/{{$product->id}}" method="post">
@method('PUT')
@csrf
<input type="text" name="test_input">
<div class="input-group number-spinner" style="border:solid 1px; width:120px;">
<span class="input-group-btn">
<button class="btn btn-default" onclick="subtract({{$product->id}})">-</button>
</span>
<!-- problemetic input -->
<input type="text" class="form-control text-center" style="border:0;background-color:#ddc2b1"
name="quantity {{$product->id}}" value="{{$product->quantity}}" id="quantity {{$product->id}}" disabled>
<span class="input-group-btn">
<button class="btn btn-default" onclick="add({{$product->id}})">+</button>
</span>
</div>
</form>
route
Route::PUT('/shopping-cart/update/{item_id}/{product_id}', 'ShoppingCartController@update');
update function
public function update($item_id , $product_id, Request $request)
{
$cart_item = ShoppingCart::find($item_id);
$cart_item->quantity = $request->input('quantity '.$product_id);
dd($request);
return redirect('/shopping-cart/view');
}
You have 2 problems here:
Your input naming. In your frontend view you name your input name="quantity {{$product->id}}"
which has a space on it. Either you remove the space or replace it with _
.
Your input attribute is disabled
. Disabled inputs are not passed to the controller. If you want it NOT editable and still want to pass the value, you can use the readonly
attribute.
So in order to solve your problem you change the input to:
<input type="text" class="form-control text-center" style="border:0;background-color:#ddc2b1"
name="quantity_{{$product->id}}" value="{{$product->quantity}}" id="quantity_{{$product->id}}" readonly>