I'm using Laravel. When I dd($request->all()) it prints data only when the array is not empty i.e. Array['some-value']. When I console.log(data) in jQuery, it logs in console that it is an array but just doesn't have any value inside. However in Laravel I can't get that empty array, but I can get it when it has value. I want to send array even if it's empty.
How can I do that?
UPDATE
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 []
}
dd($request->all());?[]but i have lots of other key/value pairs. the result when not sending the param is[['some-key' => 'some-value'], ['some-key2' => 'some-value2'], ['motions' => ['1','2','3']]]and what I want is[['some-key' => 'some-value'], ['some-key2' => 'some-value2'], ['motions' => []]]data:{motion:motionArr}