Esempio n. 1
0
 public function copyGame($key)
 {
     $copyGame = Games::where('unique_id', $key)->first();
     do {
         $unique_id = str_random(10);
     } while (Games::where('unique_id', $unique_id)->get()->count());
     $game = new Games();
     $game->game_name = $copyGame->game_name;
     $game->unique_id = $unique_id;
     $game->game_opening_statement = $copyGame->game_opening_statement;
     $game->game_ending_statement = $copyGame->game_ending_statement;
     $game->audience = $copyGame->audience;
     $game->difficulty_level = $copyGame->difficulty_level;
     $game->content_area = $copyGame->content_area;
     $game->user_id = Auth::user()->id;
     $game->save();
     $qs = Questions::where('game_id', $copyGame->id)->get();
     foreach ($qs as $qus) {
         $questions = new Questions();
         $questions->game_id = $game->id;
         $questions->question = $qus->question;
         $questions->save();
         foreach ($qus->answers as $ans) {
             $answers = new Answers();
             $answers->right_answer = $ans->right_answer;
             $answers->answer = $ans->answer;
             $answers->question_id = $questions->id;
             $answers->save();
         }
     }
     return redirect('/editor/edit/' . $game->unique_id);
 }