public static function GetFriends($user) { $userGroups = Enroll::where('user_id', $user->id)->get(); $i = 0; $d = 0; $friends = null; foreach ($userGroups as $userGroup) { $friend[$i] = Enroll::where('course_id', $userGroup->course_id)->whereNotIn('user_id', [\Auth::user()->id])->get(); foreach ($friend[$i] as $friend[$d]) { $friends[$d] = User::find($friend[$d]->user_id); $d++; } if ($friend[$i] != '[]') { $i++; } } if ($friends != null) { return array_unique($friends); } else { return $friends; } }
public function save(\Illuminate\Http\Request $request) { $points = 0; $question = Question::findOrfail(Input::get('id')); $course = $question->test()->first()->course()->first(); $this->change($request); if ($request->guess1 == 1 && $question->correct1 == 1) { $points++; } if ($request->guess2 == 1 && $question->correct2 == 1) { $points++; } if ($request->guess3 == 1 && $question->correct3 == 1) { $points++; } if ($request->guess4 == 1 && $question->correct4 == 1) { $points++; } if ($request->guess5 == 1 && $question->correct5 == 1) { $points++; } if ($request->guess1 == 1 && $question->correct1 == 0) { $points--; } if ($request->guess2 == 1 && $question->correct2 == 0) { $points--; } if ($request->guess3 == 1 && $question->correct3 == 0) { $points--; } if ($request->guess4 == 1 && $question->correct4 == 0) { $points--; } if ($request->guess5 == 1 && $question->correct5 == 0) { $points--; } $enroll = Enroll::where(['course_id' => $course->id, 'user_id' => Auth::user()->id])->first(); $enroll->points += $points; if ($enroll->points < 0) { $enroll->points = 0; } $enroll->save(); }