Example #1
0
 public function getPuzzle($slug)
 {
     $p = Puzzle::with('clues')->whereNull('puzzles.deleted_timestamp_utc')->with('puzzle_template')->where('slug', $slug)->first();
     if (!$p) {
         $returnData = array('errors' => array('Puzzle not available'));
         return response()->json($returnData, 401);
         //return array('errors' => array('Puzzle not available'));
     }
     $p->clue_squares = $p->puzzle_template->clueSquares();
     $p->puzzle_squares = $p->puzzle_squares(false);
     $template_owner = User::find($p->puzzle_template->user_id);
     $p->puzzle_template->owner = $template_owner->name;
     $p->puzzle_template->owner_username = $template_owner->username;
     $puzzle_owner = User::find($p->user_id);
     $p->owner = $puzzle_owner->name;
     $p->owner_username = $puzzle_owner->username;
     $user = Auth::user();
     if ($user) {
         $guess = PuzzleGuess::where('puzzle_id', $p->id)->where('user_id', $user->id)->first();
         if ($guess) {
             $p->solved = $guess->solved();
         } else {
             $p->solved = 0;
         }
         $p->guess_squares = $p->guess_squares($user->id);
     } else {
         $p->solved = 0;
         $p->guess_squares = array();
     }
     return $p;
 }