Skip to content

Factory count-conditional return types - #315

Open
shuvroroy wants to merge 3 commits into
PHPantom-dev:mainfrom
shuvroroy:feat/factory-count-conditional-return-types
Open

Factory count-conditional return types#315
shuvroroy wants to merge 3 commits into
PHPantom-dev:mainfrom
shuvroroy:feat/factory-count-conditional-return-types

Conversation

@shuvroroy

Copy link
Copy Markdown
Contributor

create()/make() on an Eloquent factory now resolve to the model or to a collection of models depending on whether the call-site chain set a count. See the commit message for the reasoning and the edge cases.

Worth a reviewer's attention:

  • The count state is read syntactically off the receiver chain, so a factory that travels through a variable keeps the single-model reading. That is the deliberate limit of the approach, not an oversight.
  • factory($count) only counts for a literal numeric. Larastan resolves the argument's type; we don't, and guessing wrong on a variable would silently turn one model into a collection.
  • The Factory test stub in tests/integration/completion_laravel.rs gained Laravel's real signatures (?int $count, times(), new(), the Collection<int, TModel>|TModel union). Existing factory tests pass against it unchanged.
  • test_factory_convention_based_chain_count_then_create asserted the old behaviour (count(3)->create()User) and was replaced.

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) — n/a, no new config
  • I have added/updated tests to cover my changes

@codecov-commenter

codecov-commenter commented Aug 2, 2026

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!

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.

2 participants