Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cuthbertdavies's avatar

Pivot's "boot" method

When doing 1 by 1 update inside a loop, how many is too many?

I have a pivot table, and submits a form that updates multiple rows at once. I know it's not really recommended to perform update in a loop, However, in the Pivot's "boot" method, I have setup a static::updating() hook, but if I do massive update and use sync() or upsert(), the hook is never triggered.

0 likes
1 reply
vincent15000's avatar

According to me, if you update only a few records, for example 5 or 6, you can consider that the update hook is acceptable.

What is not acceptable is if you have 100 records to update.

But these values are not official values, that's only how I code.

I don't understand why you need to trigger an update hook when updating the pivot table. Do you have any additionnal values in the pivot table ? Have you thought about using syncWithPivotValues() ?

I think that it's all the way not a good pratice to trigger an update on a pivot table. Sure you have another way to organize your code so that you can trigger this update from another part of your code than the pivot update.

Please or to participate in this conversation.