本文整理匯總了PHP中app\Question::findOrfail方法的典型用法代碼示例。如果您正苦於以下問題:PHP Question::findOrfail方法的具體用法?PHP Question::findOrfail怎麽用?PHP Question::findOrfail使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\Question
的用法示例。
在下文中一共展示了Question::findOrfail方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: save
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();
}