Exemplo n.º 1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     App\Models\Comment::truncate();
     $list = collect()->merge(App\Models\Question::all())->merge(App\Models\Answer::all());
     $users = App\Models\User::all();
     $list->each(function ($item) use($users) {
         for ($i = 0, $count = rand(0, 5); $i < $count; $i++) {
             $item->comments()->save($comment = factory('App\\Models\\Comment')->create());
             $comment->user()->associate($users->random())->save();
         }
     });
 }
Exemplo n.º 2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('answer_likes')->truncate();
     $users = App\Models\User::get();
     App\Models\Answer::all()->each(function ($answer) use($users) {
         if (rand(0, 10) < 6) {
             return;
         }
         $random_users = ($count = rand(1, 5)) ? $users->random($count) : [];
         $random_users = $count == 1 ? [$random_users] : $random_users->all();
         foreach ($random_users as $user) {
             if ($answer->user->id == $user->id) {
                 continue;
             }
             $answer->likes()->attach($user->id);
         }
     });
 }