Ejemplo n.º 1
0
 public function run()
 {
     $faker = Factory::create();
     for ($i = 1; $i <= 6; $i++) {
         $tag = new MyTag();
         $tag->text = $faker->word;
         $tag->created_at = date('Y-m-d H:i:s');
         $tag->save();
     }
 }
Ejemplo n.º 2
0
 public function run()
 {
     $tags = MyTag::all();
     $ids = $tags->lists('id');
     $total = count($ids);
     $faker = Factory::create();
     foreach (MyPost::all() as $post) {
         if (!empty($ids)) {
             // Generate random number of tags
             foreach (range(1, $faker->numberBetween(0, $total - 1)) as $value) {
                 $postTag = new MyPostTag();
                 $postTag->tag_id = $ids[$faker->numberBetween(0, $total - 1)];
                 $postTag->post_id = $post->id;
                 try {
                     $postTag->save();
                 } catch (\Exception $e) {
                     // Skip
                 }
             }
         }
     }
 }