app/Http/Controllers/api/v1/editor/CategoryController.php
// Added Soft Delete To destroy function
Added Soft Delete To destroy function
Added Soft Delete To destroy function
public function destroy($id)
    {
        $category =Category::withTrashed()->findOrFail($id);
        if (!$category->trashed())
        {
            $subCategories = Category::where('subfrom' , $category->id)->count();
            if ($subCategories){
                $status = 0;
                return jsonResponse($status, ['subfrom' => "Delete or remove sub categories first."] , $category );
            }
            $category->delete();
            $status = 1;
            $message="category Trashed successfully";
            return jsonResponse($status, $message , $category);
        }
        else
        {
            $status = 0;
            $message="you can't delete this category";
            return jsonResponse($status, $message , $category);
        }
    }
public function destroy ( $ id ) { $ category = Category :: withTrashed ( ) -> findOrFail ( $ id ) ; if ( ! $ category -> trashed ( ) ) { $ subCategories = Category :: where ( 'subfrom' , $ category -> id ) -> count ( ) ; if ( $ subCategories ) { $ status = 0 ; return jsonResponse ( $ status , [ 'subfrom' => " Delete or remove sub categories first. " ] , $ category ) ; } $ category -> delete ( ) ; $ status = 1 ; $ message = " category Trashed successfully " ; return jsonResponse ( $ status , $ message , $ category ) ; } else { $ status = 0 ; $ message = " you can't delete this category " ; return jsonResponse ( $ status , $ message , $ category ) ; } }
Added Soft Delete To destroy function
Added Soft Delete To destroy function
// check if this category has sub categories