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

[3.x] allow modification of the personal team using an optional callable #1278

Merged

Conversation

peterfox
Copy link
Contributor

@peterfox peterfox commented Mar 12, 2023

Changes

  • User Factory in the database/factories folder, specifically the withPersonalTeam method, now has a callable parameter that will apply to the factory.

Why

Allows for modification of the withPersonalTeam method so that a callable can be passed to the method to modify the team factory further, for example:

User::factory()->withPersonalTeam(
  fn (TeamFactory $factory) => $factory
    ->state([
        'foo' => 'bar',
    ])
    ->has(
        Post::factory()
            ->count(10)
    )
)
->create();

I find myself wanting this out of the box when I use Jetstream, and others would appreciate the ability to do it without copying it to their project every time. Equally, it doesn't break any compatibility.

peterfox and others added 3 commits March 12, 2023 15:12
I want this in jetstream projects, and it feels like something others would also want. It helps to set up the seeder in a Laravel Jetstream Project quickly.

For example:

```php
User::factory()->withPersonalTeam(
            fn (TeamFactory $factory) => $factory
                 ->state([
                     'foo' => 'bar',
                  ])
                 ->has(
                     Post::factory()
                          ->count(10)
                 )
)
        ->create();
```
@taylorotwell taylorotwell merged commit 62000c5 into laravel:3.x Mar 13, 2023
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