Example #1
0
 public function saveTags($dataTags)
 {
     // current tags in post
     $oldTags = $this->_tagsToArray();
     // tags form Input
     $newTags = ModelHelper::convertTagsStringToArray($dataTags);
     // save tags
     $this->_saveTags(array_diff($newTags, $oldTags));
     // detach old tags
     if (count($oldTags) > 0) {
         $this->_detachTags(array_diff($oldTags, $newTags));
     }
 }
Example #2
0
 /**
  * Store the specified resource.
  *
  * @return Response
  */
 public function store()
 {
     return ControllerHelper::ajaxWrapper(function ($data) {
         // validation data
         $validator = Validator::make($data, Post::$validationRules);
         if ($validator->fails()) {
             throw new Exception(ModelHelper::getValidationErrorsHtml($validator));
         } else {
             $post = Post::find($data['id']);
             if (is_null($post)) {
                 $post = new Post();
             }
             $post->title = trim($data['title']);
             $post->text_html = $data['text_html'];
             $post->text_markdown = $data['text_markdown'];
             if ($post->save()) {
                 $post->saveTags($data['tags']);
                 return Lang::get('post.create.ok');
             } else {
                 throw new Exception(Lang::get('post.create.db_error'));
             }
         }
     }, Input::all());
 }