Conixs

How to create a record from JSON Params?

Posted 1 month ago by Conixs

I have an endpoint that receives as params a JSON array with some information. I was able to get it using request()->operations.

However, I can't figure out how to create one operation from it.

"""
[\n
   {\n
      "collaborator_id":"132",\n
      "building_id":"40",\n
      "vehicle_plate":"123",\n
      "number_operators":"0",\n
      "activity_log":"",\n
      "lot":"",\n
      "carrier_id":"2",\n
      "number_assistants":"23",\n
      "number_tractors":"0",\n
      "cart_plate":"",\n
      "shift_id":"2",\n
      "service_id":"5",\n
      "number_samples":"0",\n
      "gross_weight":"0",\n
      "invoice_number":"",\n
      "vehicle_id":"1",\n
      "palletized_load":"0",\n
      "amount":"0",\n
      "loose_cargo":"0",\n
      "comments":"",\n
      "company_id":"7",\n
      "approver_id":"24",\n
      "number_others":"0",\n
      "cost_center":"123",\n
      "started_at":"2019-06-17 03:33:21",\n
      "cod":"",\n
      "transport_number":"",\n
      "ended_at":"2019-06-17 03:38:58"\n
   },\n
   {\n
      "collaborator_id":"132",\n
      "building_id":"61",\n
      "vehicle_plate":"213",\n
      "number_operators":"0",\n
      "activity_log":"",\n
      "lot":"",\n
      "carrier_id":"2",\n
      "number_assistants":"213",\n
      "number_tractors":"0",\n
      "cart_plate":"",\n
      "shift_id":"2",\n
      "service_id":"5",\n
      "number_samples":"0",\n
      "gross_weight":"0",\n
      "invoice_number":"",\n
      "vehicle_id":"1",\n
      "palletized_load":"0",\n
      "amount":"0",\n
      "loose_cargo":"0",\n
      "comments":"",\n
      "company_id":"4",\n
      "approver_id":"24",\n
      "number_others":"0",\n
      "cost_center":"21321",\n
      "started_at":"2019-06-17 03:36:47",\n
      "cod":"",\n
      "transport_number":"",\n
      "ended_at":"2019-06-17 03:37:22"\n
   }
]

I wish to be able to interate over it, to create $operation = new Operation();

Could someone help me?

Please sign in or create an account to participate in this conversation.