Abrar Posted August 1, 2021 Share Posted August 1, 2021 Hi Friends , We have the JSON Data coming in this format, $invoice_data = { "CONTACT_ID": "1", "INV_SERIAL_NO": "100", "NAME": "baby", "INV_DATE": "2018-06-27", "DUE_DATE": "2018-06-27", "CURRENCY": "KD", "SUBTOTAL": "143", "TAX_TOTAL": "13", "shipment_data": [ { "SHIP_SERIAL_NO": "44", "MASTER_NO": "55", "HOUSE_NO": "88", "cost_revenue_items": [ { "CHARGE_REF": "tt", "CURRENCY": "INR", "QUANTITY": "2", "SELLING_RATE": "45", "EXCHANGE_RATE": "987" },{ "CHARGE_REF": "ii", "CURRENCY": "INR", "QUANTITY": "2", "SELLING_RATE": "45", "EXCHANGE_RATE": "456" },{ "CHARGE_REF": "op", "CURRENCY": "INR", "QUANTITY": "2", "SELLING_RATE": "45", "EXCHANGE_RATE": "456" } ] } ] } How to write DELETE End-point for child data-set "cost_revenue_items". What I mean to say is how to handle the request to delete one of item from "cost_revenue_items". When "cost_revenue_items" will be deleted ,master "invoice_data" will be updated. This update , we can handle by PUT, but how do we know under that PUT, we have to DELETE one of "cost_revenue_items". Like how the JSON request to only delete one of "cost_revenue_items" will look like. Will JSON request to delete "cost_revenue_items" looks like this ,if it want to delete last record : $invoice_data = { "CONTACT_ID": "1", "INV_SERIAL_NO": "100", "NAME": "baby", "INV_DATE": "2018-06-27", "DUE_DATE": "2018-06-27", "CURRENCY": "KD", "SUBTOTAL": "143", "TAX_TOTAL": "13", "shipment_data": [ { "SHIP_SERIAL_NO": "44", "MASTER_NO": "55", "HOUSE_NO": "88", "cost_revenue_items": [ { "CHARGE_REF": "tt", "CURRENCY": "INR", "QUANTITY": "2", "SELLING_RATE": "45", "EXCHANGE_RATE": "987" },{ "CHARGE_REF": "ii", "CURRENCY": "INR", "QUANTITY": "2", "SELLING_RATE": "45", "EXCHANGE_RATE": "456" } ] } ] } Kindly help me to know , how JSON request will look like ? Thanks a lot Quote Link to comment https://forums.phpfreaks.com/topic/313464-how-to-handle-master-detail-update-and-delete-request-in-json/ Share on other sites More sharing options...
Barand Posted August 1, 2021 Share Posted August 1, 2021 You could try something like this $temp = json_decode($invoice_data); unset($temp->shipment_data[0]->cost_revenue_items[2]); $new_inv_data = json_encode($temp); echo '<pre>' . print_r($temp, 1) . '</pre>'; giving stdClass Object ( [CONTACT_ID] => 1 [INV_SERIAL_NO] => 100 [NAME] => baby [INV_DATE] => 2018-06-27 [DUE_DATE] => 2018-06-27 [CURRENCY] => KD [SUBTOTAL] => 143 [TAX_TOTAL] => 13 [shipment_data] => Array ( [0] => stdClass Object ( [SHIP_SERIAL_NO] => 44 [MASTER_NO] => 55 [HOUSE_NO] => 88 [cost_revenue_items] => Array ( [0] => stdClass Object ( [CHARGE_REF] => tt [CURRENCY] => INR [QUANTITY] => 2 [SELLING_RATE] => 45 [EXCHANGE_RATE] => 987 ) [1] => stdClass Object ( [CHARGE_REF] => ii [CURRENCY] => INR [QUANTITY] => 2 [SELLING_RATE] => 45 [EXCHANGE_RATE] => 456 ) ) ) ) ) Quote Link to comment https://forums.phpfreaks.com/topic/313464-how-to-handle-master-detail-update-and-delete-request-in-json/#findComment-1588763 Share on other sites More sharing options...
Abrar Posted August 1, 2021 Author Share Posted August 1, 2021 Hello Barand, Thanks for replying . Sorry, I could not make you understand. I want to know , how the JSON request will Look like when we want to delete one record from "cost_revenue_items". Why I am confused, because "cost_revenue_items" is nested within "$invoice_data -> "Shipment_data". So If they only want to delete only a record from "cost_revenue_items" , in what format JSON request will come ? Will it be nested and sent within parent or will be sent standalone. Quote Link to comment https://forums.phpfreaks.com/topic/313464-how-to-handle-master-detail-update-and-delete-request-in-json/#findComment-1588764 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.