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] Guess database factory model by default #39310

Merged
merged 2 commits into from
Oct 22, 2021

Conversation

nunomaduro
Copy link
Member

@nunomaduro nunomaduro commented Oct 22, 2021

At this time, database factories have this hidden feature where database models can be "guessed". As example, the following code just works:

class User extends Model
{
    use HasFactory;
}

class UserFactory extends Factory
{
    public function definition()
    {
        return [
            // ..
        ];
    }
}

User::factory()->create(); // Guesses UserFactory
UserFactory::new()->create(); // Guesses User

So, this pull request proposes that remove protected $model from the Factory stub, as probably the current "guess" logic works for 99.99% of the people. In addition, I've also pull requested to the skeleton that we remove protected $model = User::class from the UserFactory.php: laravel/laravel#5713.

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