<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Documentation;

class DocumentationController extends Controller
{
    public function index()
    {
        $documentations = Documentation::with('beneficiary')->latest()->paginate(12);
        return view('documentation.index', compact('documentations'));
    }

    public function destroy($id)
    {
        $documentation = Documentation::findOrFail($id);
        
        // Hapus file fisik jika ada
        if ($documentation->file_path && \Storage::disk('public')->exists($documentation->file_path)) {
            \Storage::disk('public')->delete($documentation->file_path);
        }
        
        $documentation->delete();

        return back()->with('success', 'Foto berhasil dihapus.');
    }
}
