В твоих js
let req = [
{ id: 1, name: 'test1' },
{ id: 2, name: 'test2' }
];
var baseurl = window.location.protocol + "//" + window.location.host;
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
url: baseurl + "/test-data",
type: 'post',
data:{
req:req
},
cache: false,
success: function(response) {
console.log(response);
}
});
В контроллере:
public function testArray(Request $request) {
$post = $request->all();
return response()->json($post);
}
В файле маршрута: (web.php)
Здесь я использовал DemoController, который вы можете заменить именем контроллера
Route::post('/test-data', 'DemoController@testArray');
Результат:
req: (2) […]
0: Object { id: "1", name: "test1" }
1: Object { id: "2", name: "test2" }
length: 2