Http/Controllers/Admin/CategoryController.php
public function store(CategoryGroup $categoryGroup, CategoryRequest $request): JsonResponse
    {
        $category = $categoryGroup->categories()->create(
            $request->only('icon')
        );

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

        $this->modifySlugs($request);

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

        if ($request->has('parent_id') && $parent = Category::find($request->input('parent_id'))) {
            $parent->appendNode($category);
        }

        dispatch(
            new RegenerateCategoryFullSlugs($category)
        );

        $this->clearCache();

        return response()->json([
            'state' => 'success',
        ]);
    }
public function store(CategoryGroup $categoryGroup, CategoryRequest $request): JsonResponse
    {
        $category = $categoryGroup->categories()->create(
            $request->only('icon')
        );

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

        $this->modifySlugs($request);

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

        if ($request->has('parent_id') && $parent = Category::find($request->input('parent_id'))) {
            $parent->appendNode($category);
        }

        dispatch(
            new RegenerateCategoryFullSlugs($category)
        );

        $this->clearCache();

        return response()->json([
            'state' => 'success',
        ]);
    }
public function store ( CategoryGroup $ categoryGroup , CategoryRequest $ request ) : JsonResponse { $ category = $ categoryGroup -> categories ( ) -> create ( $ request -> only ( 'icon' ) ) ; foreach ( $ request -> file ( 'icons' , [ ] ) as $ key => $ file ) { if ( $ categoryGroup -> hasFileIcon ( $ key ) && $ file ) { $ category -> icons ( ) -> create ( [ 'key' => $ key , 'icon' => $ file , ] ) ; } } $ this -> modifySlugs ( $ request ) ; $ category -> storeTranslations ( $ request -> input ( 'translations' ) ) ; if ( $ request -> has ( 'parent_id' ) && $ parent = Category :: find ( $ request -> input ( 'parent_id' ) ) ) { $ parent -> appendNode ( $ category ) ; } dispatch ( new RegenerateCategoryFullSlugs ( $ category ) ) ; $ this -> clearCache ( ) ; return response ( ) -> json ( [ 'state' => 'success' , ] ) ; }
Store category in the database.

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