I am trying to store multi-select input with ajax in Laravel but I am getting this error
{message: "Function name must be a string", exception: "Error", …}
here is my blade code
<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,
},
in controller
$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,
},
Please try with this.