diff --git a/src/Models/PermissionMember.php b/src/Models/PermissionMember.php index 95e3aba..59a14e2 100644 --- a/src/Models/PermissionMember.php +++ b/src/Models/PermissionMember.php @@ -19,6 +19,16 @@ class PermissionMember extends MorphPivot ]; protected $casts = [ + // member_id is a polymorphic varchar(36) that holds either a UUID + // (HasUuids host models) or a stringified bigint (auto-increment + // host models, e.g. a default User). Casting to string forces the + // value to be bound as a string in every query Eloquent builds for + // this pivot (attach / detach / where). Without it a bigint member + // key is bound as an INTEGER, and MySQL then coerces the WHOLE + // varchar column to DOUBLE to compare — which throws + // "Truncated incorrect DOUBLE value: ''" (error 1292) the + // moment a UUID-keyed member shares the same permission. + 'member_id' => 'string', 'context' => 'array', 'expires_at' => 'datetime', ]; diff --git a/src/Models/RoleMember.php b/src/Models/RoleMember.php index 4187a7d..a72e8e8 100644 --- a/src/Models/RoleMember.php +++ b/src/Models/RoleMember.php @@ -20,6 +20,16 @@ class RoleMember extends MorphPivot ]; protected $casts = [ + // member_id is a polymorphic varchar(36) that holds either a UUID + // (HasUuids host models) or a stringified bigint (auto-increment + // host models, e.g. a default User). Casting to string forces the + // value to be bound as a string in every query Eloquent builds for + // this pivot (attach / detach / where). Without it a bigint member + // key is bound as an INTEGER, and MySQL then coerces the WHOLE + // varchar column to DOUBLE to compare — which throws + // "Truncated incorrect DOUBLE value: ''" (error 1292) the + // moment a UUID-keyed member shares the same role. + 'member_id' => 'string', 'context' => 'array', 'expires_at' => 'datetime', 'created_at' => 'datetime',