0

My code is:

  $store_ids=Input::get('store_inventory_ids');
        $store_product_inven_qty=Input::get('store_pro_inv_qty');
        $store_attri_ids=Input::get('store_attri_ids');
        $store_id_with_attri_id=Input::get('store_id_attri_id');

    foreach ($store_ids as $key => $store_id) { 
    ProStoreInventoryModel::insert([
    'product_id'=>'1',
    'store_id'=>$store_id,
    'attri_ids'=>'1',
    'attri_ids_with_store_id'=>'1',
    'product_qty'=>'1',
    'status'=>'1',
    'deletestatus'=>'0',
    'created_at'=>date('Y:m:d H:i:s'),
    'updated_at'=>date('Y:m:d H:i:s')
    ]);
    }

This is my model name: ProStoreInventoryModel

The below four variable haves 16 datas in array format.,

$store_ids, $store_product_inven_qty, $store_attri_ids, 
$store_id_with_attri_id.

I just looped main foreach, in that I wrote insert query, now how can I insert the remaining values?

3
  • what do you mean by remaining value ? Commented Mar 30, 2016 at 12:31
  • These three value., $store_product_inven_qty, $store_attri_ids, $store_id_with_attri_id Commented Mar 30, 2016 at 12:46
  • The all four variable contain some set of values in array format Commented Mar 30, 2016 at 12:48

1 Answer 1

1

you can use for loop for this, eg: you have 16 inputs, do this

$store_ids=Input::get('store_inventory_ids');
$store_product_inven_qty=Input::get('store_pro_inv_qty');
$store_attri_ids=Input::get('store_attri_ids');
$store_id_with_attri_id=Input::get('store_id_attri_id');



for($i=0; $i<count($store_ids); $i++){

ProStoreInventoryModel::insert([
    'product_id'=>'1',
    'store_id'=>$store_id[$i],
    'attri_ids'=>$store_attri_ids[$i],
    'attri_ids_with_store_id'=>$store_id_with_attri_id[$i],
    'product_qty'=>$store_product_inven_qty[$i],
    'status'=>'1',
    'deletestatus'=>'0',
    'created_at'=>date('Y:m:d H:i:s'),
    'updated_at'=>date('Y:m:d H:i:s')
]);

}

OR do this

for($i=0; $i<count($store_ids); $++){

    $data[] = 
    [
        'product_id'=>'1',
        'store_id'=>$store_id[$i],
        'attri_ids'=>$store_attri_ids[$i],
        'attri_ids_with_store_id'=>$store_id_with_attri_id[$i],
        'product_qty'=>$store_product_inven_qty[$i],
        'status'=>'1',
        'deletestatus'=>'0',
        'created_at'=>date('Y:m:d H:i:s'),
        'updated_at'=>date('Y:m:d H:i:s')
    ];


}

ProStoreInventoryModel::insert($data);
Sign up to request clarification or add additional context in comments.

3 Comments

I just take the general loop and counted your input size, and grabbing one by one input values
which section you didn't understand ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.