framework
framework copied to clipboard
[11.x] Fix type mismatch in Polymorphic Relationships When Using PostgreSQL
fixes #54401
The changes introduce a "string" default morph type via schema and eloquent relationship.
Global
To combine uuid or ulid with int globally.
Illuminate\Database\Schema\Builder::defaultMorphKeyType('string');
Per relationship
Alternatively, you can manually set it per table using either $table->nullableStringableMorphs('owner') or $table->stringableMorphs('owner') method.
Next, define the relationship using:
public function integrations()
{
return $this->morphMany(Owner::class, 'owner', morphKeyType: 'string');
}
or
public function integrations()
{
return $this->morphMany(Owner::class, 'owner')->morphKeyType('string');
}