<?php

namespace App\Http\Controllers\Api\cms;

use Illuminate\Http\Request;
use App\Models\cms\Image;

class ImageController extends Controller
{
    public function deleteImage(Request $request)
    {
        $image = Image::find($request->id);
        if($image){
            // public_path(Storage::delete($document->attachment));
            if(file_exists(public_path($image->image_url))){
                // delete the file
                unlink(public_path($image->image_url));
            }
            $image->delete();
            return response()->json(['success' => 'Image deleted successfully']);
        } else {
            return response()->json(['error' => 'Image not found']);
        }
    }
}
