Skip to content

Conversation

@zigzagdev
Copy link

what i have done

This PR replaces the incorrect use of is_subclass_of() with instanceof in the getRelatedModelFromRelation() method.

When the relation method returns an actual instance (f.e. BelongsTo, HasMany, etc.), is_subclass_of() returns false, since it expects a class name string.

This caused false negatives when verifying Eloquent relation types.

why

  • is_subclass_of() checks class inheritance on class names, not on instances, leading to incorrect results.
  • Using instanceof correctly identifies Relation instances and their subclasses (BelongsTo, HasMany, MorphTo, etc.).
  • This change aligns with PHP’s expected type-checking semantics and avoids false negatives.

Tests

throws RelationNotFoundException when the relation method exists but does not return an Eloquent Relation

result
スクリーンショット 2025-11-05 17 37 47

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant