php - Laraval 5: How to handle nested objects in json request -


i started working on laravel 5. sending json request controller. works fine simple json. have scenario json this

{ "orders":[         {           "user_id":"1",           "product_id":"10"         },         {             "user_id":"1",           "product_id":"15"         },     ] } 

it can more complex nested objects. inside controller have been doing like

<?php namespace app\http\controllers;  use illuminate\http\request; use app\http\requests; use app\http\controllers\controller;  class orderscontroller extends controller  {     public function __construct( request $request)     {       //$this->middleware('products.prodcutslist');     }      public function makeorder(request $request)     {         $order_data= $request->only('orders');         print_r($order_data);     } } 

response looks

array (     [orders] =>  ) 

please guide how can in array. thanks

i'm not sure resolve problem json not correct have remove comma in end :

{ "orders":[         {           "user_id":"1",           "product_id":"10"         },         {             "user_id":"1",           "product_id":"15"         }, //remove comma  _________^      ] } 

note : can use following pretty website validate json jsonformatter.

hope helps.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -