Ejemplo n.º 1
0
 /**
  * Get logged user with his details.
  *
  * @return array
  */
 public function getSessionUser()
 {
     $id = Session::get('login')['userid'];
     $user = User::where(['UserID' => $id])->firstOrFail();
     $userdetails = Userdetail::where(['UserID' => $id])->firstOrFail();
     return ['Username' => $user->Username, 'Email' => $user->Email, 'FirstName' => $userdetails->FirstName, 'LastName' => $userdetails->LastName, 'Birthday' => $userdetails->Birthday, 'Address' => $userdetails->Address, 'PostalCode' => $userdetails->PostalCode, 'City' => $userdetails->City, 'State' => $userdetails->State, 'Country' => $userdetails->Country, 'Phone' => $userdetails->Phone, 'MobilePhone' => $userdetails->MobilePhone];
 }
Ejemplo n.º 2
0
 public function create(Request $request)
 {
     //
     $data = $request->json()->all();
     $scoreschange = 0;
     for ($i = 0; $i < count($data); $i++) {
         $userdetail = Userdetail::where('user_id', $data[$i]['user_id'])->where('cat_id', $data[$i]['cat_id'])->where('question_id', $data[$i]['question_id'])->limit(1);
         if (count($userdetail->get()) == 0) {
             $scoreschange += $data[$i]['is_correct'];
             Userdetail::create(['user_id' => $data[$i]['user_id'], 'cat_id' => $data[$i]['cat_id'], 'question_id' => $data[$i]['question_id'], 'is_correct' => $data[$i]['is_correct']]);
         } else {
             foreach ($userdetail->get() as $u) {
                 $scoreschange += $data[$i]['is_correct'] - $u->is_correct;
             }
             $userdetail->update(['is_correct' => $data[$i]['is_correct']]);
         }
     }
     $user_id = $data[0]['user_id'];
     $this->updateScore($user_id, $scoreschange);
     return Response::json('ok');
     //redirect()->route('pages.index');
 }