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

ayekoto's avatar

Laravel[or PHP] is rounding up my primary keys to the nearest 100

Hi,

I'm currently generating 64-bits ID for my app. Modeled after Twitter Snowflake's Service.

The problem is when parsing a Model to JSON or sometimes internally. The id gets rounded to the nearest 100.

So if i have a resource with an ID like 582624899457581056 in the database. When converted to JSON response i get ID 582624899457581000.

This of course is problematic.

My current workaround is to cast all ID to string. However i'm hoping someone might be able to help me.

What i've tried so far. I've verified that my php installation is a 64-bit installation. I've also modified the ini settings like ini_set('precision', -1); and ini_set('serialize_precision', -1);. This doesn't fix the issue though [and i have since reverted].

Has anyone come across similar issues?

0 likes
1 reply
camachojua's avatar

Do you tried to keep the ID's on a BigInteger datatype?

Please or to participate in this conversation.