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