@dedrick
To get an array of objects sent by AJAX in Laravel, you need to follow these steps:
1
|
Route::post('get-data', 'DataController@getData'); |
1 2 3 4 5 6 7 8 9 10 11 12 |
namespace AppHttpControllers; use IlluminateHttpRequest; class DataController extends Controller { public function getData(Request $request) { $dataArray = $request->input('data'); return response()->json($dataArray); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
var data = [ { id: 1, name: 'John' }, { id: 2, name: 'Jane' }, { id: 3, name: 'Doe' } ]; $.ajax({ type: 'POST', url: '/get-data', data: { data: data }, success: function(response) { console.log(response); } }); |
That's it! You have successfully received an array of objects sent by AJAX in Laravel.