<?php

namespace App\Http\Controllers\API;

use App\Http\Controllers\Controller;
use App\Models\TravelPlace;
use App\Models\Destination;
use App\Models\DestinationImage;

class TravelPlaceController extends Controller
{
    public function index()
    {
        return response()->json(TravelPlace::all());
    }

public function show($id)
{
    $dest = Destination::with('images')->find($id);

    if (!$dest) {
        return response()->json(['message' => 'Not found'], 404);
    }

    // Modify image paths
    $dest->images->transform(function ($image) {
        $image->image_url = url('images/package_sub_images/' . rawurlencode($image->image));
        return $image;
    });

    return response()->json(['data' => $dest], 200);
}

}
