gpt4 book ai didi

javascript - 使用 Laravel 和 Ajax 获取日期数据

转载 作者:行者123 更新时间:2023-12-03 02:01:30 26 4
gpt4 key购买 nike

我的数据库中有一个数据,其中有 2 个名为registrations 的表,ssi_tracks 我需要根据 track_first_status 显示注册表数据。我需要按日期过滤数据并将其显示在数据表上

具有自定义功能的 Controller 文件

public function datewise(Request $request, $data_end, $data_start){


$data_start->$request->input('start_date');
$data_end->$request->input('end_date');


$datewise=DB::table('registrations')
->join('ssi_tracks', 'registrations.registration_id', '=', 'ssi_tracks.registration_id')
->select('address', 'model', 'chassis', 'delivery_date')
->where([["ssi_tracks.track_first_status", "=", 0]])
->whereBetween('created_at',[$data_start, $data_end])
->get();

$output = "";
$count = 1;
foreach ($datewise as $reg) {

$output .= '<tr>' .
'<td>' . $count++ . '</td>' .
'<td>' . $reg->address . '</td>' .
'<td>' . $reg->model . '</td>' .
'<td>' . $reg->chassis . '</td>' .
'<td>' . $reg->delivery_date . '</td>' .
'<td>' . '<button class="btn btn-primary btn-rounded button">Call Customer
</button>'. '</td>' .

'</tr>';


}
return response()->json($output);
}

Ajax函数

<script>

$(function () {
$("#start_date").datepicker();
$("#end_date").datepicker();
});
$('#filter').click(function () {
let start_date = $('#start_date').val();
let end_date = $('#end_date').val();
if (start_date !== '' && end_date !== '') {
$.ajax({
url: "{{url("date")}}",
method: "get",
data: {
start_date: start_date,
end_date: end_date
},
success: function (data) {
// $('#listdetails').html(data);
console.log(data);
}
});
} else {
alert("Please Select Date");
}
});
});


</script>

索引文件包含日期输入类型

 <label>From
</label> <input type="date" name="start_date" id="start_date" class="form-control"
style="width:150px;">
<label>To</label> <input type="date" name="end_date" id="end_date" class="form-control"
style="width:150px;">
<button class="btn btn-info" id="filter" name="filter" >Filter</button>

最佳答案

您可以使用此代码,

public function datewise(Request $request){

$data_start = $request->input('start_date');
$data_end = $request->input('end_date');


$datewise=DB::table('registrations')
->join('ssi_tracks', 'registrations.registration_id', '=', 'ssi_tracks.registration_id')
->select('address', 'model', 'chassis', 'delivery_date')
->where([["ssi_tracks.track_first_status", "=", 0]])
->whereBetween('created_at',[$data_start, $data_end])
->get();

$output = "";
$count = 1;
foreach ($datewise as $reg) {

$output .= '<tr>' .
'<td>' . $count++ . '</td>' .
'<td>' . $reg->address . '</td>' .
'<td>' . $reg->model . '</td>' .
'<td>' . $reg->chassis . '</td>' .
'<td>' . $reg->delivery_date . '</td>' .
'<td>' . '<button class="btn btn-primary btn-rounded button">Call Customer
</button>'. '</td>' .

'</tr>';


}
return response()->json($output);
}

关于javascript - 使用 Laravel 和 Ajax 获取日期数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49998572/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com