我可以在scrpit数组上获取数组值。
脚本是
$(document).on('click', '#bulk_delete', function()
{
var id = [];
if(confirm("Are you sure you want to Delete this data?"))
{
$('.student_checkbox:checked').each(function(){
id.push($(this).val());
});
if(id.length > 0)
{
$.ajax({
url:"del",
method:"get",
data:{id:id},
success:function(data)
{
alert(data);
$('#dTable').DataTable().ajax.reload();
}
});
}
else
{
alert("Please select atleast one checkbox");
}
}
});
如何将这些数组值获取到laravel控制器并插入数据库中
路线是
Route::get('/del', 'AjaxdataController@ins');
并且AjaxdataController.php是
public function ins(Request $request )
{
}
尝试像这样从ajox更改ajax的方法类型。
只需在控制器中编写以下代码。您将在那儿检索从ajax传递的id。
// Controller
public function insertSchedule(Request $request)
{
$employAdd = [];
foreach($employAdd as $key){
$employeeTimeSet = new Schedule;
$employeeTimeSet->employee_no = $request->input('hidEmployeeno');
$employeeTimeSet->last_name = $request->input('hidEmployeeLast');
$employeeTimeSet->first_name = $request->input('hidEmployeeFirst');
$employeeTimeSet->date_today = $request->input('dateToday');
$employeeTimeSet->time_in = $request->input('timeIn');
$employeeTimeSet->time_out = $request->input('timeOut');
$employeeTimeSet->save();
}
}
// View
{!! Form::open(['action' => 'Admin\EmployeeFilemController@insertSchedule', 'method' => 'POST']) !!}
<div class="row">
<div class="form-group col-md-12">
<small>Employee No. and Name: </small><b><i> {{ $employee->employee_no }} : {{ $employee->last_name }}, {{ $employee->first_name }}</i></b>
<input type="hidden" name="hidEmployeeno[]" value='<?php echo $employee->employee_no ?>'>
<input type="hidden" name="hidEmployeeLast[]" value='<?php echo $employee->last_name ?>'>
<input type="hidden" name="hidEmployeeFirst[]" value='<?php echo $employee->first_name ?>'>
<hr>
</div>
</div>
@php
$today = today();
$dates = [];
for($i=1; $i < $today->daysInMonth + 1; ++$i) {
$dates[] = \Carbon\Carbon::createFromDate($today->year, $today->month, $i)->format('F-d-Y');
}
@endphp
<table class="table">
<thead>
<tr>
<th>DATE TODAY</th>
<th>TIME IN</th>
<th>TIME OUT</th>
<th>ACTION</th>
</tr>
</thead>
<tbody>
@foreach($dates as $date)
// See here my view? the dates here are arrays then when I insert this into the database the output or the data that is being inserted is the last data why is that?