-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
Is it currently possible to achieve something like this?
We have the relationship:
Order -> hasMany -> OrderItems
I want to create an order with a status of new and then create 4 order items with a status of allocated. Is it possible to hook into the orderItemFactory method from within the with method, and apply the allocated status?
// Test
OrderFactory::new()
->withOrderItems(5)
->create();
// OrderFactory.php
public function withOrderItems($qty)
{
return $this->with(
OrderItem::class,
'orderItems',
$qty
);
}
// OrderItemFactory.php
public function allocated()
{
return tap(clone $this)->overwriteDefaults([
'state' => 'allocated',
]);
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels