-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Closed
Description
- Laravel Version: 5.5.40
- PHP Version: 7.1.13-nts
Description
There are many pairs of models. Syncing Associations.I've set my primary key to be a string, but belongsToMany::sync
The return is an integer, which overflows the integer and cannot get the correct result.This leads me to make an error on the primary key.
Steps To Reproduce:
hotelIds = $request->input('hotel_id', []);
$changes = $user->hotels()->sync($hotelIds);
event(new HotelUserEvent($user, $changes));
Screen
Steps To fix the issue:
# \Illuminate\Database\Eloquent\Relations\Concerns\InteractsWithPivotTable::class
protected function castKey($key)
{
// whether the current key is greater than the largest integer.
if ((int)bcsub($key, PHP_INT_MAX) > 0) {
return (string)$key;
}
return is_numeric($key) ? (int)$key : (string)$key;
}
Metadata
Metadata
Assignees
Labels
No labels