示例#1
0
 /**
  * @param Request $request
  * @return array
  */
 public function getUser(Request $request)
 {
     $return = [];
     try {
         $userModel = new User();
         $user = $userModel->findByPhone("+1" . $request->route('phone'));
         // format data based on user role
         switch ($user->role) {
             case 'expert':
                 // fetch expert's responses and associated submissions
                 $responseModel = new Response();
                 $responses = $responseModel->where('user_id', $user->id)->with('submission.user')->get();
                 $data = $user->toArray();
                 $data['photos'] = $responses;
                 $return = $this->formatExpertUser($data);
                 break;
             case 'enthusiast':
                 // fetch enthusiast's submissions and associated responses
                 $submissionModel = new Submission();
                 $submissions = $submissionModel->where('user_id', $user->id)->with('response.user')->get();
                 $data = $user->toArray();
                 $data['photos'] = $submissions;
                 $return = $this->formatEnthusiastUser($data);
                 break;
         }
     } catch (\Exception $e) {
         // return some dummy data
         $return = $this->dummyResponse();
     }
     return $this->respondOK($return);
 }
 /**
  * @param Submission $submission
  * @param User $expert
  * @param boolean $wasSquirrel
  * @return static
  */
 public function saveResponse(Submission $submission, User $expert, $wasSquirrel)
 {
     $response = $this->responseModel->create(['submission_id' => $submission->id, 'user_id' => $expert->id, 'is_squirrel' => $wasSquirrel]);
     return $response;
 }