The order of my inverse polymorphic relationships affects the result obtained when displaying the columns of each model.
For example: I have this relationship
final class Person extends Model
{
public function personable(): MorphTo
{
return $this->morphTo();
}
}
final class PersonResource extends RestResource
{
public static $model = Person::class;
public function relations(RestRequest $request): array
{
return [
MorphTo::make('personable', PhysicalPeopleResource::class), ---> placed 1st
MorphTo::make('personable', MoralPeopleResource::class),
];
}
}
But when I change the order of my relationships I get a different result
final class Person extends Model
{
public function personable(): MorphTo
{
return $this->morphTo();
}
}
final class PersonResource extends RestResource
{
public static $model = Person::class;
public function relations(RestRequest $request): array
{
return [
MorphTo::make('personable', MoralPeopleResource::class),
MorphTo::make('personable', PhysicalPeopleResource::class), ---> placed 2nd
];
}
}
Create two models of person types, physical and moral, both with different columns (id, created_at and updated_at are in both models)
When creating the MorphTo relationship from the People resource, the order in which each relationship is called is important since it depends on whether or not it shows you the corresponding columns of each model
Laravel Rest Api Version
2.7
Laravel Version
10.14.1
PHP Version
8.1.3
Database Driver & Version
No response
Description
The order of my inverse polymorphic relationships affects the result obtained when displaying the columns of each model. For example: I have this relationship
and I get this result
But when I change the order of my relationships I get a different result
and I get this result
Only columns that match in both models are shown
Steps To Reproduce