Reputation: 111
I'm trying to save multipliable ids in the database using loop but it only save the last id 3 times so I made for loop to test it
for ($i = 0; $i < 10; $i ++)
{
$this->product_id = $i;
$this->shop_name = $shop;
$this->save();
}
it saves number 9 three times and stops ????
This issue never happened before
Upvotes: 2
Views: 47
Reputation: 163838
You need to create a new instance with each iteration, for example:
for ($i = 0; $i < 10; $i++) {
$this->create(['product_id' => $i, 'shop_name' => $shop]);
}
Your code updates a single instance multiple times.
Upvotes: 4