Level 102
Put it in a variable that can be used to resolve sub_unit
$unit = fake()->randomElement(['A', 'B', 'C', 'D', 'E']);
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
if I want a factory to choose randomElement from an array, based on the previous result:
'unit' => fake()->randomElement(['A', 'B', 'C', 'D', 'E']),
'sub_unit' => // in case of 'A', select randomElement from array that belongs to 'A'.. etc
Is there a convenient way, or I will somehow need to create a function that gets the previous result?
Put it in a variable that can be used to resolve sub_unit
$unit = fake()->randomElement(['A', 'B', 'C', 'D', 'E']);
Please or to participate in this conversation.