Example #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $products = Product::all();
     foreach ($products as $product) {
         $this->attachImages($product);
     }
 }
Example #2
0
 private function attachRelated($product)
 {
     $rand = rand(0, 3);
     $related = Product::orderBy(DB::raw('RAND()'))->take($rand)->get();
     foreach ($related as $item) {
         $product->related()->attach($item);
     }
 }