/** * Update the specified resource in storage. * * @param CategoryRequest $request * @param int $id * @return Response */ public function update(CategoryRequest $request, $id) { // everything was validated by ArticleRequest, ready to save $input = $request->except('_token'); $category = Category::updateOrCreate(['id' => $id], $input); // this should be the url to the article $url = '/' . $category->path . '/index'; if ($category) { if ($request->ajax()) { return ['response' => 'success', 'next' => $url]; } return redirect($url)->with('success', 'Category saved.'); } return back()->withInput(); }