/** * Update the specified rating in storage. * * @param int $id * @return Response */ public function update($id) { $rating = Rating::findOrFail($id); $validator = Validator::make($data = Input::all(), Rating::$rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } $rating->update($data); return Redirect::route('ratings.index'); }
/** * Update the specified rating in storage. * * @param int $id * @return Response */ public function update($id) { $userId = Auth::user()->id; $ratingData = Rating::find($id); if ($userId === $ratingData["user_id"]) { $rating = Rating::findOrFail($id); $messages = array('new_stars.required' => 'We need to know how many stars you wish to give!', 'new_stars.max' => 'You must enter a value with a maximum value of 5.', 'new_comment.max' => 'You must enter a value with a maximum of 255 characters.', 'new_recommended.max' => 'You must enter a value with a maximum of 255 characters.'); $validator = Validator::make($data = Input::all(), Rating::$new_rules, $messages); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } else { $rating->stars = Input::get('new_stars'); $rating->comment = Input::get('new_comment'); $rating->recommended = Input::get('new_recommended'); $result = $rating->save(); } if ($result) { Session::flash('successMessage', 'Your rating was successfully updated'); return Redirect::route('ratings.index'); } else { Session::flash('errorMessage', 'Please properly input all the required fields'); Log::warning('Rating failed to save: ', Input::all()); return Redirect::back()->withInput(); } } else { return "Access Denied: this is not your rating."; } }