Harsh Narigra
Harsh Narigra

Reputation: 15

Hello here i am having this problem of passing multiple data In form

As you can see here I am looping with foreach but it only sends the one product_name (last one) of the cart, but I Want to send every product_name.

<form method="POST" action="{{route('order.store')}}">
    @csrf
    @method('POST')
            
    @foreach(Cart::content() as $item)
        <input type="hidden" name="product_name" value="{{$item->name}}">
    @endforeach
</form>

            

Upvotes: 0

Views: 48

Answers (2)

A.A Noman
A.A Noman

Reputation: 5270

You have to use like input name as array

<input type="hidden" name="product_name[]" value="{{$item->name}}">

Upvotes: 1

zahid hasan emon
zahid hasan emon

Reputation: 6233

you have to use an array to send multiple values using the same name attribute.

@foreach(Cart::content() as $item)
    <input type="hidden" name="product_name[]" value="{{$item->name}}">
@endforeach

this will send each product name and you have to loop through to get every one in the backend.

Upvotes: 0

Related Questions