I am trying to update multiple rows of data with existing foreign key values where basket
should only link to the foreign ID of 100
.
Example:
id | title | basket_id (foreign key to another table) |
---|---|---|
1 | apple | 100 |
2 | banana | 200 |
2 | kiwi | 300 |
What I have tried:
$fruits = Fruit::whereIn('basket', [200, 300])->get();
foreach ($fruits as $fruit) {
$fruit->update([
"basket_id" => 100
])
}
This works fine, however, when I print $fruit
, I am still getting the old basket_id
in the relations
attribute in eloquent.
Am I missing a step?
Thanks