コード例 #1
0
ファイル: ArticlesController.php プロジェクト: Panfen/mango
 public function update(Requests\CreateArticleRequest $request, $id)
 {
     $article = Article::findOrFail($id);
     $oldCateId = $article->cate_id;
     $article->update($request->all());
     $oldTags = Tag::where(['user_id' => \Auth::user()->id, 'article_id' => $id])->delete();
     $newTags = $request->get('tags');
     if ($newTags && $newTags != "多个标签以,分隔") {
         $newTags = str_replace(',', ',', $newTags);
         //中文状态逗号,替换成英文逗号
         $newTags = trim($newTags, ',');
         $arr = explode(',', $newTags);
         //拆分标签入库
         foreach ($arr as $k => $v) {
             Tag::create(array('tag' => $v, 'user_id' => \Auth::user()->id, 'article_id' => $article->id));
         }
     }
     //更新分类数据
     if ($oldCateId != $request->get('cate_id')) {
         //有分类的文章才执行原有分类自增
         if ($article->cate_id > 0) {
             Cate::where('id', $oldCateId)->decrement('count');
             Cate::where('id', $request->get('cate_id'))->increment('count');
         } else {
             //
         }
     }
     return redirect('/articles');
 }