Laravel Database Query Builder insertGetId() method always returning 2147483647

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
results:

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
is 2147483647.

To solve this issue, find this file at your vendor folder:
\vendor\laravel\framework\src\Illuminate\Database\Query\Processors\Processor.php

Find the processInsertGetId() function and modify its typecasting from int() to float().
From

return is_numeric($id) ? (int) $id : $id;

To

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’;