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] Change __call factory and relation resolution #33439

Merged
merged 1 commit into from
Jul 6, 2020
Merged

[8.x] Change __call factory and relation resolution #33439

merged 1 commit into from
Jul 6, 2020

Conversation

bastien-phi
Copy link
Contributor

This PR aims to resolve 2 problems we could have using magic forXX and hasXX of Illuminate\Database\Eloquent\Factories\Factory

1 : Inconsistency of parameter given to factoryForModel
As described in laravel/ideas#2284, if App\User uses Illuminate\Database\Eloquent\Factories\HasFactory, calling App\User::factory() will call Factory::factoryForModel with 'App\User' whereas calling PostFactory::forUser will call it with 'user'. IMHO it should always be called with the fully qualified class name.

2 : Relations are not always called by related model name
It is common to have relation named by something else than the related model name. For example, if a post belongs to a user, the post relation can be named author.
This PR allows developer to call $postFactory()->forAuthor() to create the post's author.

@GrahamCampbell GrahamCampbell changed the title Change __call factory and relation resolution [8.x] Change __call factory and relation resolution Jul 6, 2020
@taylorotwell taylorotwell merged commit 223293a into laravel:master Jul 6, 2020
@bastien-phi
Copy link
Contributor Author

Thanks !

@bastien-phi bastien-phi deleted the improve_eloquent_factory_call branch July 6, 2020 15:43
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