Example #1
0
 /**
  * @param User|Shop $owner
  */
 private function seedShippingPlans($owner)
 {
     // create 3 shipping plans for seller
     $shippingPlans = $owner->shippingPlans()->saveMany(factory(ShippingPlan::class, 3)->make());
     $shippingPlans->each(function (ShippingPlan $shippingPlan) {
         $shippingPlan->shippingOptions()->saveMany(factory(ShippingOption::class, 3)->make());
     });
     // assign a random plan to 80% of products
     $products = $owner->products()->get();
     foreach ($products as $product) {
         if ($this->faker->boolean(80)) {
             /** @var Product $product */
             $product->shippingPlans()->attach($shippingPlans->random()->id);
         }
     }
 }
 /**
  * @param User|Shop $seller
  */
 private function seed($seller)
 {
     $seller->shippingPlans()->saveMany(factory(ShippingPlan::class, 3)->make())->each(function (ShippingPlan $shippingPlan) {
         $shippingPlan->shippingOptions()->saveMany(factory(ShippingOption::class, 3)->make());
     });
 }