public function saveDocumentEdits($documentId)
 {
     if (!Auth::check()) {
         return Redirect::to('documents')->with('error', 'You must be logged in');
     }
     $content = Input::get('content');
     $contentId = Input::get('content_id');
     if (empty($content)) {
         return Redirect::to('documents')->with('error', "You must provide content to save");
     }
     if (!empty($contentId)) {
         $docContent = DocContent::find($contentId);
     } else {
         $docContent = new DocContent();
     }
     if (!$docContent instanceof DocContent) {
         return Redirect::to('documents')->with('error', 'Could not locate document to save');
     }
     $document = Doc::find($documentId);
     if (!$document instanceof Doc) {
         return Redirect::to('documents')->with('error', "Could not locate the document");
     }
     if (!$document->canUserEdit(Auth::user())) {
         return Redirect::to('documents')->with('error', 'You are not authorized to save that document.');
     }
     $docContent->doc_id = $documentId;
     $docContent->content = $content;
     try {
         DB::transaction(function () use($docContent, $content, $documentId, $document) {
             $docContent->save();
         });
     } catch (\Exception $e) {
         return Redirect::to('documents')->with('error', "There was an error saving the document: {$e->getMessage()}");
     }
     //Fire document edited event for admin notifications
     $doc = Doc::find($docContent->doc_id);
     Event::fire(MadisonEvent::DOC_EDITED, $doc);
     try {
         $document->indexContent($docContent);
     } catch (\Exception $e) {
         return Redirect::to('documents')->with('error', "Document saved, but there was an error with Elasticsearch: {$e->getMessage()}");
     }
     return Redirect::to('documents')->with('success_message', 'Document Saved Successfully');
 }
 /**
  * 	PUT route for saving documents.
  */
 public function putDocs($id = '')
 {
     $user = Auth::user();
     if (!$user->can('admin_manage_documents')) {
         return Redirect::to('/dashboard')->with('message', "You do not have permission");
     }
     $content = Input::get('content');
     $content_id = Input::get('content_id');
     if ($content_id) {
         try {
             $doc_content = DocContent::find($content_id);
         } catch (Exception $e) {
             return Redirect::to('dashboard/docs/' . $id)->with('error', 'Error saving the document: ' . $e->getMessage());
         }
     } else {
         $doc_content = new DocContent();
     }
     $doc_content->doc_id = $id;
     $doc_content->content = $content;
     $doc_content->save();
     Event::fire(MadisonEvent::DOC_EDITED, $doc);
     $doc = Doc::find($id);
     $doc->indexContent($doc_content);
     return Redirect::to('dashboard/docs/' . $id)->with('success_message', 'Document Saved Successfully');
 }