Я использую Laravel.Когда я dd($request->all())
, он печатает данные только тогда, когда массив не пустой, т.е. Array['some-value']
.Когда я console.log(data)
в jQuery, он регистрирует в консоли, что это массив, но просто не имеет никакого значения внутри.Однако в Laravel я не могу получить этот пустой массив, но я могу получить его, когда он имеет значение.Я хочу отправить массив, даже если он пуст.
Как я могу это сделать?
ОБНОВЛЕНИЕ
HTML:
<ul>
<!-- It sends but doesn't show in Laravel when this active class below is not exists -->
<li class="active" data-motion="1">motion 1</li>
<li data-motion="2">motion 2</li>
<li data-motion="3">motion 3</li>
</ul>
JQuery:
$.each($('ul li.active'), function(index, motion) {
motion = $(motion).attr('data-motion');
params['motions'].push(motion);
});
// it shows the empty array when that active class is not there,
// which is the one I want to get in Laravel too.
consol.log(params);
$.ajax({
url: '/my-motions',
type: 'PUT',
dataType: 'json',
data: params,
success: function(response) {
params = [];
},
error: function(error) {
//
}
});
Laravel:
public function myFunc(Request $request)
{
$data = $request->all();
dd($data);
// The result: nothing
// What I want: array:0 []
}