/** * Run the database seeds. * * @return void */ public function run() { $categories = Category::all(); foreach ($categories as $category) { $this->attachImages($category); } }
private function attachCategories($product) { $rand = rand(0, 3); $categories = Category::orderBy(DB::raw('RAND()'))->take($rand)->get(); foreach ($categories as $category) { $product->categories()->attach($category); } }
/** * Run the database seeds. * * @return void */ public function run() { Category::buildTree($this->generateTree()); }