/** * Update the specified resource in storage. * * @param int $id * @param EditCategoryRequest $request * @return Response */ public function update($id, EditCategoryRequest $request) { $category = Category::findOrFail($id); $category->fill($request->all()); $category->save(); $message = trans('messages.edited_category_successfully'); Flash::info($message); return redirect()->route('admin.categories.edit', $category); }
/** * Updates category attributes from form * * @param Request $request * @param \App\Models\Category $category * @return View */ public function update(EditCategoryRequest $request, Category $category) { // Set and save validated attributes $category->name = $request->input('name'); $category->slug = $request->input('slug'); $category->save(); /** * If parent is set and if parent_id and category->id are not equal, * set parent category */ $parentId = $request->input('parent_id'); if (empty(trim($parentId))) { $category->makeRoot(); } else { $parentCategory = Category::findOrFail($parentId); $category->makeChildOf($parentCategory); } return redirect(route('AdminCategoryIndex')); }