I need to save data from this array to MySQL database
0 => {#517 ▼
+"id": 59
+"name": "example_name_1"
+"category": "category_1"
+"price": 100
+"description": "example_description_1"
}
1 => {#516 ▼
+"id": 60
+"name": "example_name_2"
+"category": "category_2"
+"price": 200
+"description": "example_description_2"
}
I am tryinig to save like this, but reveive errors like
Undefined index: name
for ($idx = 0; $idx < count($products); $idx++)
{
$values = new Product();
$values->name = $products["name"][$idx];
$values->category= $products["category"][$idx];
$values->description = $products['description'][$idx];
$values->price = $products['price'][$idx];
$values->save();
}
productsto understand how to use it. You have to use aforeach ($products as $product) { $product->name ... }