Http/Controllers/Admin/CategoryController.php
public function destroy(CategoryGroup $categoryGroup, Category $category): JsonResponse
    {
        $categories = $categoryGroup->categories()->descendantsAndSelf(
            $category->id
        );

        foreach ($categories as $item) {
            $item->delete();
        };

        $this->clearCache();

        return response()->json([
            'state' => 'success',
        ]);
    }
public function destroy(CategoryGroup $categoryGroup, Category $category): JsonResponse
    {
        $categories = $categoryGroup->categories()->descendantsAndSelf(
            $category->id
        );

        foreach ($categories as $item) {
            $item->delete();
        };

        $this->clearCache();

        return response()->json([
            'state' => 'success',
        ]);
    }
public function destroy ( CategoryGroup $ categoryGroup , Category $ category ) : JsonResponse { $ categories = $ categoryGroup -> categories ( ) -> descendantsAndSelf ( $ category -> id ) ; foreach ( $ categories as $ item ) { $ item -> delete ( ) ; } ; $ this -> clearCache ( ) ; return response ( ) -> json ( [ 'state' => 'success' , ] ) ; }
Delete category and it's descendants.

@param \Modules\Category\Models\CategoryGroup $categoryGroup
@param \Modules\Category\Models\Category $category
@return \Illuminate\Http\JsonResponse
Delete category and it s descendants .