public function update(TestResultRequest $request, $id) { $user = User::findOrFail($request->input('row_id')); $test = Test::findOrFail($id); $result = TestResult::where('user_id', $user->id)->where('test_id', $test->id); $score = $request->input('value'); if ($result->count()) { if (!empty($score)) { $result->update(['score' => $score]); } else { $result->delete(); } } else { TestResult::create(['user_id' => $user->id, 'test_id' => $test->id, 'score' => $score]); } return $request->input('value'); }
/** * Update the specified resource in storage. * * @param TestRequest $request * @param int $id * * @return Response */ public function update(TestRequest $request, $id) { Test::findOrFail($id)->update($request->all()); return redirect(action('TestController@index')); }