Program api
This commit is contained in:
@@ -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);
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user