我试图在Laravel中存储ajax的多选择输入,但我得到这个错误
{message: "Function name must be a string", exception: "Error", …}
这是我的刀片代码
<select class="" multiple="" id="medicine_pills" name="medicine_pills[]">
<option value="2">test</option>
<option value="2">test</option>
</select>
var medicine_pills = $('#medicine_pills').val();
$.ajax({
url: '{{ url('medicine') }}',
type: "post",
data: {
'_token': "{{ csrf_token() }}",
'medicine_pills': medicine_pills,
'last_appointment_id': last_appointment_id,
},
在控制器
$medicines = request()->post('medicine_pills');
foreach ($medicines as $iteam) {
echo $medicines;
$user = Medicine::create([
'medicines_cats' => $iteam,
'appointmen_id' => $last_appointment_id,
]);
<select class="" multiple="" id="medicine_pills" name="medicine_pills[]">
<option value="2">test</option>
<option value="2">test</option>
</select>
var medicine_pills = $("input[name='medicine_pills[]']").val();
$.ajax({
url: '{{ url('medicine') }}',
type: "post",
data: {
'_token': "{{ csrf_token() }}",
'medicine_pills': medicine_pills,
'last_appointment_id': last_appointment_id,
},
请试试这个