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] Use Generic Models on Factories #39165

Closed
wants to merge 3 commits into from
Closed

[8.x] Use Generic Models on Factories #39165

wants to merge 3 commits into from

Conversation

aidan-casey
Copy link

This pull request adds generic models to Laravel factories. The benefit of this is that there will be better autocompletion and static analysis support for methods on the model (e.g., relationship methods, helper methods, etc.).

For example, the following code will autocomplete in IDEs that support it:

/**
 * @extends Factory<User>
 */
class UserFactory extends Factory
{
    protected $model = User::class;

    public function definition()
    {
        // ...
    }
}

UserFactory::new()
    ->create()
    ->getAuthIdentifier();

@fragkp
Copy link
Contributor

fragkp commented Oct 11, 2021

Already closed: #38654

@aidan-casey
Copy link
Author

aidan-casey commented Oct 11, 2021

Hey @fragkp, this PR takes a slightly different approach than the one you referenced and is more in line with the updates being made to collections, etc. Per a conversation with @nunomaduro on Twitter, I am hoping there is an opportunity for this to get merged. 🙂

@nunomaduro nunomaduro self-requested a review October 11, 2021 20:58
@nunomaduro
Copy link
Member

#39169

@nunomaduro nunomaduro closed this Oct 12, 2021
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