/**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Requests\StoreArticleRequest $request, $id)
 {
     //
     $article = Article::findOrFail($id);
     $input = $request->all();
     $article->update($input);
     return redirect('/articles');
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  Requests\StoreArticleRequest   $request
  * @return Response
  */
 public function store(Requests\StoreArticleRequest $request)
 {
     $input = $request->all();
     $input['intro'] = mb_substr($request['content'], 0, 250) . '......';
     $article = Article::create($input);
     $tags = $this->separateTags($request['tags']);
     $this->saveTags($article, $tags);
     return Redirect::route('home');
 }
示例#3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Requests\StoreArticleRequest $request)
 {
     $input = $request->all();
     //下面增加两行,顺便看看Request::get的使用
     $input['intro'] = mb_substr($request->get('content'), 0, 64);
     Article::create($input);
     return redirect('/');
     /**
              * $validator = Validator::make($input, [
             'title' => 'required|min:3',
             'body' => 'required',
             ]);
             然后可以使用下面这样的方式来检查验证有没有通过:
     
             if ($validator->fails())
             {
     */
 }
示例#4
0
 /**
  * 修改文章功能
  * @param Requests\StoreArticleRequest $req
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function update(Requests\StoreArticleRequest $req)
 {
     $input = $req->except('id');
     $input['intro'] = mb_substr($input['content'], 0, 64);
     $onlyInput = $req->only('id', 'tag_list');
     // 获取要修改的文章模型
     $article = Article::with('hasOneDetail')->find($onlyInput['id']);
     // 需要更新的数据
     $article->update($input);
     $article->hasOneDetail->update($input);
     // 跟attach()类似,用sync()来同步标签
     if (!is_null($onlyInput['tag_list'])) {
         $article->tags()->sync($onlyInput['tag_list']);
     } else {
         $article->tags()->detach();
     }
     return redirect('/');
 }
 /**
  * ajax添加文章
  * 
  * @param        
  * 
  * @author        wen.zhou@bioon.com
  * 
  * @date        2015-09-20 05:59:09
  * 
  * @return        
  */
 public function store(StoreArticleRequest $request)
 {
     $article = Article::create(['title' => $request->input('title'), 'catagory' => $request->input('catagory'), 'content' => $request->input('content'), 'html_content' => $request->input('html_content')]);
     return response()->json(['msg' => '文章添加成功']);
 }