Stack Exchange
undefine index in laravel 5.8 multiple text fields insertion
undefine index in laravel 5.8 multiple text fields  insertions
i have tried to insert multiple data into mysql table at once but everytime i click on submit button laravel keeping telling me Undefined index: product_sku.i have tried so many ways to solve the problem but i was unable to solve it.
this is my controller
$random_sku= Str::random(10);

$productDetails= Product::with('attributes')->where(['id'=>$id])->first();

//$productsDetails= json_decode(json_encode($productsDetails));

if($request->isMethod('post')){
    $data=$request->all();
    foreach($data['product_sku'] as $key=>$value){
        if(!empty($value)){
            //Prevent SKU Duplication SKU Check
            $attCountSKUSeller=ProductAttributes::where('product_sku',$value)->count();
            if($attCountSKUSeller>0){
                return redirect('/seller-add-product-attributes/'.$id)->with('flash_message_error','product SKU already exists, please add another Product SKU!');
            }
            //Prevent Size Duplication Check
            $attrcountSizesSeller= ProductAttributes::where(['product_id'=>$id, 'product_size'=>$data['product_size'][$key]])->count();
            if($attrcountSizesSeller > 0){
                return redirect('/seller-add-product-attributes/'.$id)->with('flash_message_error','"'.$data['product_size'][$key].'" Size already exists for this product, please add another Size!');
            }

            $attribute=new ProductAttributes;
            $attribute->product_id=$id;
            $attribute->product_sku=$value;
            $attribute->product_size=$data['product_size'][$key];
            $attribute->product_price=$data['product_price'[$key];
            $attribute->product_colour=$data['product_colour'][$key];
            $attribute->product_stock=$data['product_stock'][$key];
            $attribute->save();
        }
    }
    return redirect('/seller-add-product-attributes/'.$id)->with('flash_message_success','Product(s) Attribute(s) have been Added Successfully');
}

return view('shop.seller_product_attributes')->with(compact('productDetails', 'random_sku'));

//return view('shop.seller_product_attributes');

This is my view:
<form class="card-body" action="{{url('/seller-add-product-attributes/'.$productDetails->id)}}" method="post">
    <input type="hidden" name="_token" value="{{csrf_token()}}">
    <div class="form-group" id="dynamic_form">
        <div class="row">
            <!-- <input type="hidden" name="product_sku" id="product_sku"  value="{{$random_sku}}">-->
            <div class="col-md-2 col-sm-2 col-lg-2 col-xs-2">
                <label for="product_price">Price</label>
                <input type="text" name="product_price[]" id="product_price" placeholder="Price" class="form-control mb-3" validate="number" >
            </div>
            <div class="col-md-2 col-sm-2 col-lg-2 col-xs-2">
                <label for="product_size">Size</label>
                <select class="browser-default custom-select custom-select mb-3" name="product_size[]" id="product_size" >
                    <option selected disabled>Select Size</option>
                    <option>Small</option>
                    <option>Big</option>
                    <option>Extra Large</option>

                </select>
            </div>

            <div class="col-md-2 col-sm-2 col-lg-2 col-xs-2">
                <label for="product_colour">Colour</label>
                <input type="text" name="product_colour[]" id="product_colour" placeholder="Colour" class="form-control mb-3" validate="name" >
            </div>
            <div class="col-md-2 col-sm-2 col-lg-2 col-xs-2">
                <label for="product_stock">Stock</label>
                <input type="number" name="product_stock[]" id="product_stock" placeholder="Quantity" class="form-control mb-3" >
            </div>

            <div class="button-group mt-4 my-2">
                <a href="javascript:void(0)" class="btn btn-primary  btn-sm" id="plus5">Add More</a>
                <a href="javascript:void(0)" class="btn btn-danger btn-sm" id="minus5">Remove</a>
            </div>
        </div>
    </div>
    <div class="row d-flex justify-content-center ">
        <button type="submit" class="btn btn-primary btn-block text-center mb-4 mx-2">Submit</button>
    </div>
</form>

I have tried so many laravel helper functions to do this like create() that uses mass assignable, insert() .Pls, i want to know how to do this properly because i have been on this thing for like 4 days now.Any help will be appreciated.Thanks in advance.

i have removed the comment.still thesame thing

i have already  removed the comment still thesame thing

Pls , help me i have been on these for the past four days

This is a fairly simple problem. You don't have any product_sku input in your view(it is commented out).
