A
A
Alexander2021-06-09 12:22:07
Laravel
Alexander, 2021-06-09 12:22:07

How to do Seeding with predefined data dependent on each other?

I have Model Product
Also I have Model Feature and Model FeatureValue.

I want to generate

Product->FeatureValue(Many values)-Feature

EloquentProduct::factory->has(
  EloquentCharacteristicValue::factory()
            ->count(3)
            ->for(
                EloquentCharacteristic::factory(),
                'characteristic'
            )
)->create();


Problems:
1) Values ​​are predefined. When creating, you need to compare the Characteristics with the desired Values ​​​​of the characteristics. For example, if CharacteristicValue = Red, you would create Characteristic=Color. You also need to check. If the database already has such a characteristic, then you do not need to create, but select an existing one
2) You need to randomly generate different CharacteristicsValues ​​for the product, in different quantities

Color
Red
Blue
Green
Black
White
Warranty
12 months
24 months
36 months

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question