Beispiel #1
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());
 }