public function updateCategory(Request $request)
    {
        $this->validate(
            $request,
            [
                'category_id'        => 'required|integer|exists:categories',
                'parent_category_id' => 'integer|exists:categories,category_id',
                'name'               => 'required',
                'slug'               => 'required',
            ]
        );

        $category = Category::find($request->input('category_id'));

        $parent = Category::find($request->input('parent_category_id'));

        if (in_array($request->input('parent_category_id'), $category->getDescendantIds())) {
            return redirect()->back()->withErrors(['parent_category_id' => trans('mustard::admin.category_parent_is_child')]);
        }

        $category->parent()->associate($parent);
        $category->name = $request->input('name');
        $category->slug = $request->input('slug');

        $category->save();

        return redirect()->back()->withStatus(trans('mustard::admin.category_updated'));
    }
public function updateCategory(Request $request)
    {
        $this->validate(
            $request,
            [
                'category_id'        => 'required|integer|exists:categories',
                'parent_category_id' => 'integer|exists:categories,category_id',
                'name'               => 'required',
                'slug'               => 'required',
            ]
        );

        $category = Category::find($request->input('category_id'));

        $parent = Category::find($request->input('parent_category_id'));

        if (in_array($request->input('parent_category_id'), $category->getDescendantIds())) {
            return redirect()->back()->withErrors(['parent_category_id' => trans('mustard::admin.category_parent_is_child')]);
        }

        $category->parent()->associate($parent);
        $category->name = $request->input('name');
        $category->slug = $request->input('slug');

        $category->save();

        return redirect()->back()->withStatus(trans('mustard::admin.category_updated'));
    }
public function updateCategory ( Request $ request ) { $ this -> validate ( $ request , [ 'category_id' => 'required|integer|exists:categories' , 'parent_category_id' => 'integer|exists:categories,category_id' , 'name' => 'required' , 'slug' => 'required' , ] ) ; $ category = Category :: find ( $ request -> input ( 'category_id' ) ) ; $ parent = Category :: find ( $ request -> input ( 'parent_category_id' ) ) ; if ( in_array ( $ request -> input ( 'parent_category_id' ) , $ category -> getDescendantIds ( ) ) ) { return redirect ( ) -> back ( ) -> withErrors ( [ 'parent_category_id' => trans ( 'mustard::admin.category_parent_is_child' ) ] ) ; } $ category -> parent ( ) -> associate ( $ parent ) ; $ category -> name = $ request -> input ( 'name' ) ; $ category -> slug = $ request -> input ( 'slug' ) ; $ category -> save ( ) ; return redirect ( ) -> back ( ) -> withStatus ( trans ( 'mustard::admin.category_updated' ) ) ; }
Update a category.

@return \Illuminate\Http\RedirectResponse
Update a category .