Program api

This commit is contained in:
2026-05-26 00:55:51 +07:00
parent 037c482649
commit 9231f25e5d
5 changed files with 165 additions and 1 deletions
@@ -0,0 +1,33 @@
<?php
namespace App\Http\Resources\Core;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use App\Http\Resources\Core\ProgramKomoditasResource;
use App\Http\Resources\Core\ProgramLokasiResource;
class ProgramResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'nama' => $this->nama,
'sub_domain' => $this->sub_domain,
'tahun' => $this->tahun,
'instansi' => $this->instansi,
'komoditas' => $this->komoditas()->with('komoditas')->get()->map(function ($item) {
return new ProgramKomoditasResource($item);
}),
'lokasi' => $this->lokasi()->with(['provinsi', 'kabupatenKota', 'kecamatan', 'desaKelurahan'])->get()->map(function ($item) {
return new ProgramLokasiResource($item);
}),
];
}
}