/** * Update the counselor associated with the attendee. * * @param int $id * @return \Illuminate\Http\Response */ public function updateCounselor($id) { $attendee = Attendee::find($id); if (!$attendee) { return $this->respondNotFound('Attendee does not exist.'); } $counselorId = Input::get('counselor_id'); if (!$counselorId) { return $this->respondUnprocessableEntity('Parameters failed validation for an attendee.'); } try { $newCounselor = Counselor::findOrFail($counselorId); } catch (ModelNotFoundException $e) { return $this->respondUnprocessableEntity('Counselor provided does not exist'); } //We pass validation. Now softDelete the existing counselor and replace it. $currentCounselor = $attendee->counselor; if ($currentCounselor->id != $newCounselor->id) { $attendee->reassignCounselor($newCounselor->id); return $this->respond(['message' => "The attendee/counselor assignment has been updated."]); } return $this->respond(['message' => "The attendee/counselor assignment remains unchanged."]); }