Example #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @throws Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  * @return Response
  */
 public function update(ArticleRequest $request, $id)
 {
     $this->request = $request;
     $this->getCategory();
     // everything was validated by ArticleRequest, ready to save
     $input = $request->except('_token');
     $article = Article::updateOrCreate(['id' => $id], $input);
     // this should be the url to the article
     $url = '/' . $this->category->path . '/' . $article->slug;
     if ($request->ajax()) {
         return ['response' => 'success', 'next' => $url];
     }
     if ($article) {
         return redirect($url)->with('success', 'Article saved.');
     }
     return back()->withInput();
 }