I've a bunch of problems with this matter. Assume following POST (i'm using KnockoutJS to convert my object to json), where i'm posting inside http form data.
$.post('uri', {data: ko.toJSON(data)}, function(response){ // Handle response }, 'json'); This is what's happening inside my controller
<?php // 1. My plain input is here, and it's a slash-encoded string, // like { foo: \"bar\"} $input = \Input::get('data'); // 2. Input::json() is empty, maybe because jquery // posts in the http form data instead of posting in payload. $input = \Input::json(); So, to get my data out of the Input i have to
$input = stripcslashes($input); dd(json_decode($input)); Assume that $.post() call can not be changed, i only want to approach this server side.
I think L4 should provide someway the parsed input, and i think i shouldn't be doing any stripslashes. So, what am i doing wrong?
== EDIT ==
Thanks to fideloper answer and comments, im gonna change something, since there's actually something wrong in the client side $.post (which, anyway, is not the point of this question). So, here's what new javascript will look like (data is still being posted as application/x-www-form-urlencoded):
$.post('uri', ko.toJSON(data), function(response){ // Handle response }, 'json'); What's happening now on server side?
dd(\Input::all()); // < --- Contains nothing (array()) dd(\Input::json->all()); // < --- Contains data array, as expected What is confusing me is this piece of documentation, from L4 Requests&Input
Note: Some JavaScript libraries such as Backbone may send input to the application as JSON. You may access this data via Input::get like normal.
In this case i can not access data via Input::get. Again: whats wrong?
ko.toJSON(data). Try send data without using toJSON method.