Example #1
0
 public function postCheckArticle()
 {
     $checked = Input::get('checked');
     $draftArticle = DraftArticle::where('id', '=', Input::get('id'))->first();
     if ($checked == "true") {
         $draftArticle->status = '003';
         $article = Article::firstOrNew(array('draft_article_id' => $draftArticle->id));
         $article->title = $draftArticle->title;
         $article->content = $draftArticle->content;
         $article->cover = $draftArticle->cover;
         $article->digest = $draftArticle->digest;
         $article->user_id = $draftArticle->user_id;
         $article->content_format = $draftArticle->content_format;
         $article->save();
         $article->pictures()->delete();
         foreach ($draftArticle->pictures as $picture) {
             $articlePicture = App::make("ArticlePicture");
             $articlePicture->article_id = $article->id;
             $articlePicture->path = $picture->path;
             $articlePicture->thumbnail = $picture->thumbnail;
             $articlePicture->desc = $picture->desc;
             $article->pictures()->save($articlePicture);
         }
     } else {
         $draftArticle->status = '004';
     }
     $draftArticle->memo = Input::get('memo');
     if ($draftArticle->save()) {
         $response['success'] = true;
     } else {
         $response['success'] = false;
         $response['message'] = '保存失败。';
     }
     return Response::json($response);
 }