MoFish
2 months ago

Add Array Form Field

Posted 2 months ago by MoFish

Hi,

I have a form field called product which is an array:

<input type="text" name="product[]" class="form-control" value="{{$d->id}}" />

I'm simply trying to save all the products but i am hitting issues.

$product = Input::get('product');
$dataSet = [];
foreach ($product as $p) {
    $dataSet[] = [
        'barcode'    => $p
];
}
            
DB::table('product')->insert($dataSet);

Getting the following error:

Invalid argument supplied for foreach()

What have I done wrong? :/ Is there a nicer way to do this?

Thanks

Please sign in or create an account to participate in this conversation.