Skip to content

Support custom Eloquent pivot accessor names - #381

Merged
AJenbo merged 2 commits into
PHPantom-dev:mainfrom
shuvroroy:feat/customizing-the-pivot-attribute-name
Sep 7, 2026
Merged

Support custom Eloquent pivot accessor names#381
AJenbo merged 2 commits into
PHPantom-dev:mainfrom
shuvroroy:feat/customizing-the-pivot-attribute-name

Conversation

@shuvroroy

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #266 based on review feedback about Laravel’s custom pivot accessor names.

Many-to-many relationships using ->as('participation') now expose $participation on the related model instead of $pivot. The accessor retains the configured pivot model type for completion, hover, and chained member access.

This also supports:

  • Literal accessor names from BelongsToMany’s fourth generic.
  • Pivot types supplied by the third generic or ->using(...).
  • Multiple differently named pivot accessors targeting the same model.
  • Safe handling of dynamic ->as($name) calls without synthesizing an incorrect property.
  • Existing declared properties without overwriting or duplicating them.

Relationship hover information now includes the custom pivot accessor. The Laravel demo and changelog have also been updated.

Performance

  • Accessor and related-model names use interned atoms.
  • The reverse index uses identity-hashed atom keys.
  • Relationship metadata is looked up once per relationship.
  • Target classes are cloned only when an accessor actually needs to be injected.
  • Accessor parsing avoids temporary string allocations

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, examples/)
  • I have updated the config schema (config-schema.json)
  • I have added/updated tests to cover my changes

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

shuvroroy added a commit to shuvroroy/phpantom_lsp that referenced this pull request Aug 20, 2026
@AJenbo
AJenbo force-pushed the feat/customizing-the-pivot-attribute-name branch from 20b7b3c to d1a3043 Compare September 7, 2026 08:40
@AJenbo
AJenbo merged commit fc644ac into PHPantom-dev:main Sep 7, 2026
8 checks passed
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.

3 participants