В поле зрения
<script type = "text/javascript" >
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content');
}
});
function sendData() {
// Your nested JS array goes here
var data = [
{
"1" : {0 : "topi",1 : "pensil",2 : "baju"}
},
{
"2" : {0 : "kertas",1 : "kertas"}
},
{
"3" : {0 : "botol"}
}
];
$.ajax({
url: '/test',
type: 'POST',
dataType: 'json',
contentType: 'json',
data: JSON.stringify(data),
contentType: 'application/json; charset=utf-8',
});
}
</script>
В контроллере
function saveJson(Illuminate\Http\Request $request)
{
$data = json_decode($request->getContent());
}