<?php

namespace App\Traits;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;

trait DeleteAttachment
{
    public function deleteAttachment(string $path, Model $classModel): void
    {
        if ($classModel->attachment && $classModel->attachment->formatted_attachment) {
            Storage::delete("$path/{$classModel->attachment->formatted_attachment}");
            $classModel->attachment->delete();
        }
    }
}
