Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Add support for dynamic 'for' methods on factories with existing model instances #35579

Closed
wants to merge 1 commit into from
Closed

[8.x] Add support for dynamic 'for' methods on factories with existing model instances #35579

wants to merge 1 commit into from

Conversation

bakerkretzmar
Copy link
Contributor

Adds support for attaching existing model instances using dynamic forModel() syntax. Follow-up to #35494 and #35541.

For example, to attach a User model via an author() relationship that uses the author_id column:

$posts = Post::factory(10)
    ->forAuthor($user = User::factory()->create())
    ->create();

See #35494 (comment).

@bakerkretzmar
Copy link
Contributor Author

Never mind, I forgot that the dynamic methods expect an array, not a factory. We talked about adding this before and decided it would be confusing. I think it makes more sense to just specify the relationship explicitly with something like ->for($user = User::factory()->create(), 'author').

@bakerkretzmar bakerkretzmar deleted the fix-dynamic-for-with-existing-models branch December 11, 2020 15:56
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