kali ini kita coba memanggil fungsi contoller lain dari laravel yang mengharuskan parameter post dengan return balik json yang
berikut caranya
lokasi controller 1 : App\Http\Controllers\Main\Pengadaan\PengadaanChecklist;
nama file controller 1 : PengadaanChecklist.php
nama method : PengadaanChecklist()
return controler 1:
return response()->json([
‘data’ => $data,
‘sign’=>$tanda
]);
contoller pemanggil
import dulu
use App\Http\Controllers\Main\Pengadaan\PengadaanChecklist; //untuk fungsi -fungsi bantuan
$myRequest = new \Illuminate\Http\Request();
$myRequest->setMethod(‘POST’);
$myRequest->request->add([‘kodepengadaan’ => $kodepengadaan]);
//PengadaanChecklist PengadaanChecklist_obj = new PengadaanChecklist();
$tampil_list_petugas= (new PengadaanChecklist)->PengadaanPanitiaChecklistGetList($myRequest);
untuk mengambil datanya
$tampil_list_petugas->getData()->data;
referensi :
- https://www.itsolutionstuff.com/post/how-to-call-a-controller-function-in-another-controller-in-laravelexample.html
- https://stackoverflow.com/questions/40188597/how-to-access-a-property-value-inside-jsonresponse-object-in-php-or-laravel
- https://stackoverflow.com/questions/40262947/create-a-laravel-request-object-on-the-fly
- https://stackoverflow.com/questions/37107903/in-laravel-is-there-a-way-to-add-values-to-a-request-array
- https://stackoverflow.com/questions/47126882/attributes-vs-original-in-laravel-when-dd


tinggalkan pesan