When you are using Laravel insertGetId() method to insert a record and retrieve the ID
and is consistently 2147483647 value, but when you check the database it is not the normal
value you would expect, it is because your PHP is running in 32bit mode and the range of
the int value on this mode is -2,147,483,648 to 2,147,483,647.
To find out if you are running 32bit or 64bit, upload this script to your server and view the
echo (PHP_INT_SIZE * 8) . ‘-bit’;
insertGetId() is typecasting the return value to int() so if your insert id is
higher than this value (2147483648 above), the method will return the int max value which
To solve this issue, find this file at your vendor folder:
Find the processInsertGetId() function and modify its typecasting from int() to float().
return is_numeric($id) ? (int) $id : $id;
return is_numeric($id) ? (float) $id : $id;
I hope in the future releases we can have some sort of a config option like in Eloquent
where we can set the typecasting like:
* The “type” of the auto-incrementing ID.
* @var string
protected $keyType = ‘float’;