lukeraymonddowning / poser

Create class based model factories in Laravel applications in seconds.
MIT License
277 stars 10 forks source link

Generating relationships of different states #45

Closed RileyDavidson closed 4 years ago

RileyDavidson commented 4 years ago

Hi.

I want to generate different factory states inside my With() statements.

Example

$user = UserFactory::new()

Essentially I want to generate 15 'returning customers' and 15 'first time customers'.

I realise this syntax most likely isn't correct (as I couldn't get it to work) but in the readme I can't figure out the correct way to accomplish this. I only see the way to apply multiple states to the same record.

Sorry if I'm just missing something simple!

lukeraymonddowning commented 4 years ago

Hi @RileyDavidson!

Thanks for creating this issue! Really appreciate it. I've just released a patch update (2.3.1-beta) that sorts this issue.

The syntax for this would be as follows:

$user = UserFactory::new()
->withCustomers(CustomerFactory::times(15)->state('first_time_customer'))
->withCustomers(CustomerFactory::times(15)->state('returning_customer'))
->create();
andreich1980 commented 4 years ago

you've missed one ) in the end of the first with method ;)

lukeraymonddowning commented 4 years ago

you've missed one ) in the end of the first with method ;)

Hey I created this thing, doesn't mean I know how to use it! 😂

andreich1980 commented 4 years ago

It was super fast. Like 2 hours from the issue was created 👍

lukeraymonddowning commented 4 years ago

Move fast, break nothing

RileyDavidson commented 4 years ago

Wow! Yeah that was super fast, I appreciate it.

I'll get the latest version and test it out!