Пытаюсь передать переменные через Ajax в Laravel 5.1
Ajax:
$.ajaxSetup({
headers: {
'Content-Type':'application/json',
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
contentType: "application/json",
dataType: 'JSON',
type: "post",
url: '/orders/api/store',
data: {
_method: 'post',
_token: CSRF_TOKEN,
message: '123',
id: 1,
},
success: function( response ) {
console.log(response);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus); alert("Error: " + errorThrown);
}
});
Routes.php:
Route::post('/orders/api/store', 'OrdersController@apiStore');
И сама функция обрабочтик:
public function apiStore(Request $request) {
$response = [
'request' => request('message'),
'message' => 'works',
'status' => '200'
];
return response()->json($response);
}
Результат выполнения следующий:
{request: null, message: "works", status: "200"}
При попытке считать переменную message возвращается null