35 lines
1.1 KiB
PHP
35 lines
1.1 KiB
PHP
<?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,
|
|
'nama_singkat' => $this->nama_singkat,
|
|
'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);
|
|
}),
|
|
];
|
|
}
|
|
}
|