Exemplo n.º 1
0
 protected function productBases($amount)
 {
     $brands = Brand::all();
     $categories = Category::whereNull('original_id')->get();
     $categories->load('synonyms');
     $accounts = Account::take(2)->get();
     foreach ($accounts as $account) {
         for ($i = 0; $i < $amount; $i++) {
             $product = factory(Product::class)->create(['brand_id' => $brands->random(1)->id, 'account_id' => $account->id]);
             $this->addImages($product);
             $category = $categories->random(1);
             $categoryIds = [$category->id];
             if ($category->synonyms) {
                 $categoryIds = array_merge($categoryIds, $category->synonyms->lists('id')->toArray());
             }
             $product->categories()->sync($categoryIds);
             $this->properties($product, $category);
             $this->prices($product, $account->id);
             $this->promotions($product, $account->id);
         }
     }
 }