/** * 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'); }
/** * 保存文章功能 * @param Requests\StoreArticleRequest $req * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function store(Requests\StoreArticleRequest $req) { $info = $req->all(); $info['intro'] = mb_substr($info['content'], 0, 64); $article = Article::create($info); $article->tags()->attach($info['tag_list']); $article->hasOneDetail()->create(['detail' => $info['detail']]); return redirect('/'); }
/** * 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()) { */ }