topvillas's avatar

Factories with Different Attributes

Suppose I'm writing a test to check that only models with a specific status are shown.

Is there a SIMPLER way to use a factory to generate a certain number of model with one status and more models with another? I'm currency using two factory calls and it seems a bit clunky to me.

SomeModel::factory()->count(10)->create([
     'status' => 'LIVE'
]);	

SomeModel::factory()->count(5)->create([
     'status' => 'DRAFT'
]);
0 likes
3 replies
s4muel's avatar

sure, np. and i also found in documentation, that: The $index property contains the number of iterations through the sequence that have occurred thus far so if you use closure, you can switch from one state to another after e.g. 10 iterations, if needed at all

1 like

Please or to participate in this conversation.