Http/Controllers/Admin/CategoryController.php
public function update(CategoryRequest $request, CategoryGroup $categoryGroup, Category $category): JsonResponse
    {
        if ($category->category_group_id !== $categoryGroup->id) {
            abort(404);
        }

        $category->update(
            $request->only('icon')
        );

        foreach ($request->file('icons', []) as $key => $file) {
            if ($categoryGroup->hasFileIcon($key) && $file) {
                $category->icons()->updateOrCreate(
                    ['key' => $key],
                    ['icon' => $file]
                );
            }
        }

        $this->modifySlugs($request);

        $category->updateTranslations(
            $request->input('translations')
        );

        dispatch(
            new RegenerateCategoryFullSlugs($category)
        );

        $this->clearCache();

        return response()->json([
            'state' => 'success',
        ]);
    }
public function update(CategoryRequest $request, CategoryGroup $categoryGroup, Category $category): JsonResponse
    {
        if ($category->category_group_id !== $categoryGroup->id) {
            abort(404);
        }

        $category->update(
            $request->only('icon')
        );

        foreach ($request->file('icons', []) as $key => $file) {
            if ($categoryGroup->hasFileIcon($key) && $file) {
                $category->icons()->updateOrCreate(
                    ['key' => $key],
                    ['icon' => $file]
                );
            }
        }

        $this->modifySlugs($request);

        $category->updateTranslations(
            $request->input('translations')
        );

        dispatch(
            new RegenerateCategoryFullSlugs($category)
        );

        $this->clearCache();

        return response()->json([
            'state' => 'success',
        ]);
    }
public function update ( CategoryRequest $ request , CategoryGroup $ categoryGroup , Category $ category ) : JsonResponse { if ( $ category -> category_group_id !== $ categoryGroup -> id ) { abort ( 404 ) ; } $ category -> update ( $ request -> only ( 'icon' ) ) ; foreach ( $ request -> file ( 'icons' , [ ] ) as $ key => $ file ) { if ( $ categoryGroup -> hasFileIcon ( $ key ) && $ file ) { $ category -> icons ( ) -> updateOrCreate ( [ 'key' => $ key ] , [ 'icon' => $ file ] ) ; } } $ this -> modifySlugs ( $ request ) ; $ category -> updateTranslations ( $ request -> input ( 'translations' ) ) ; dispatch ( new RegenerateCategoryFullSlugs ( $ category ) ) ; $ this -> clearCache ( ) ; return response ( ) -> json ( [ 'state' => 'success' , ] ) ; }
Update category in the database.

@param \Modules\Category\Http\Requests\CategoryRequest $request
@param \Modules\Category\Models\CategoryGroup $categoryGroup
@param \Modules\Category\Models\Category $category
@return \Illuminate\Http\JsonResponse
Update category in the database .