Decode laravel 4 Input::json()
You can use ->get()
to access properties from a Symfony\Component\HttpFoundation\ParameterBag
response.
$input = Input::json();$input->get('firstName')
You can also get all inputs as an array and then type cast it to an object with (object)
. Note that this will throw an error if your property doesn't exists, so if I where you, I would use the ->get()
method mentioned above.
$input = (object)Input::all();$input->firstName;
Based on my experiment
If you are sending an array of multiple objects like the following example from the Javascript using JSON
[{crop_id: 1, test_id: 6},{crop_id: 1, test_id: 7},{crop_id: 1, test_id: 8}]
You need to use Input::json()->all() function in PHP.
$arr = Input::json()->all();$crop_id = $arr[0]['crop_id'];$test_id = $arr[0]['test_id'];