Skip to content

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