SHARE
TWEET

Untitled

a guest Jun 25th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function random(Module $module, $name){
  2.     // Get all questions for module.
  3.  
  4.     $questions = $module->questions->shuffle()->pluck('id');
  5.  
  6.     // Get unseenQuestions
  7.  
  8.     $sessionName = 'unseenQuestions_' . $name .  strval($module->id); //unseenQuestions_all_2
  9.  
  10.     if (session()->has($sessionName)) {
  11.         $unseenQuestions = session()->get($sessionName);
  12.  
  13.     } else {
  14.         $unseenQuestions = collect($questions);
  15.  
  16.     }
  17.  
  18.     // Pop new Question
  19.  
  20.     $newQuestionID = $unseenQuestions->shift();;
  21.  
  22.     // Store unseenQuestions OR remove unseenQuestions (if it has no items)
  23.  
  24.     if ($unseenQuestions->count() == 0) {
  25.         session()->forget($sessionName);
  26.     } else {
  27.         session()->put($sessionName, $unseenQuestions);
  28.     }
  29.  
  30.     return new QuestionResource(Question::find($newQuestionID));
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top