uzkurama's avatar

How to make Factory(Seeder) with Nested RelationShips

Getting an error when I seed my table, "order_details_id doesn't have a default value", but I pointed to all relationships as said in documentation. What's wrong with my code, please give advice or a solution

class OrdersSeeder extends Seeder
{
    public function run()
    {
        $inventory = Inventory::all()->random();
        $details = OrderDetails::factory();
        $markets = OrdersMarkets::factory()->count(2);
        $inventories = OrdersInventories::factory()->count(2);
        $orders = Orders::factory()
            ->has($details->count(2)
                ->hasAttached(
                    $inventories, ['inventory_id' => $inventory->id], 'inventories'
                )
                ->hasAttached(
                    $markets, ['market_id' => $inventory->market_id], 'markets'
                ), 'order_details'
            )
            ->count(10000)
            ->create();
    }
}

0 likes
0 replies

Please or to participate in this conversation.