Ejemplo n.º 1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $posts = Post::all();
     $categories = Category::all();
     foreach ($categories as $category) {
         $subPosts = $posts->take(3);
         foreach ($subPosts as $post) {
             $post->addToCategory($category);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     $posts = Post::all();
     $tags = Tag::all()->toArray();
     foreach ($posts as $post) {
         $ts = $faker->randomElements($tags, $faker->numberBetween(0, 8));
         foreach ($ts as $tag) {
             $post->assignTag($tag['id']);
         }
     }
 }