【发布时间】:2026-02-10 18:15:02
【问题描述】:
您好,我想将我的 daterange 过滤器的值设置为像今天这样的实时是 2021 年 4 月 5 日,所以我的 daterange 过滤器的默认值变成了从 2021 年 4 月 5 日到 2021 年 4 月 5 日,并且还显示了我的数据库中的数据,应该我愿意吗?
这是我的视图刀片:
<form action="searchdateinvoice" method="get">
@csrf
<div class="container">
<div class="row">
<div class="container-fluid">
<div class="form-group row">
<label for="date" class="col-form-label col-sm-1" style="width: 99px">Date From</label>
<div class="col-sm-3">
<input type="date" class="form-control input-sm" value="2021-04-05"name="dateFrom" id="dateFrom" required>
</div>
<label for="date" class="col-form-label col-sm-1">Date To</label>
<div class="col-sm-3">
<input type="date" class="form-control input-sm " value="2021-04-05"name="dateTo" id="dateTo" required>
</div>
<div class="col-sm-3">
<button type="submit" class="btn btn-primary pl-4 pr-4 rounded-pill" style="background-color: #B10000" title="searchdate"> <span
class="pl-1">Filter</button>
</div>
</div>
</div>
</div>
</div>
</form>
@if (count($indexInvoices) > 0)
<table class="table table-bordered table-hover" class="display" cellspacing="0">
<thead style="background-color: #B10000">
<tr>
<th class="text-center text-light" scope="col">No.</th>
<th class="text-center text-light" style="width:10%" scope="col">Sale Date</th>
<th class="text-center text-light" scope="col">Invoice</th>
<th class="text-center text-light" scope="col">Sender</th>
<th class="text-center text-light" scope="col">Status</th>
</tr>
</thead>
<tbody>
@foreach ($indexInvoices as $invoice)
<tr>
<th class="align-middle" scope="row">{{ $loop->iteration }}</th>
<th class="align-middle" scope="row">
@php
$old_date = explode('-', $invoice->saledate);
$new_data = $old_date[2] . '-' . $old_date[1] . '-' . $old_date[0];
echo $new_data;
@endphp
</th>
<th class="align-middle" scope="row">{{ $invoice->saleno }}</th>
<th class="align-middle" scope="row">{{ $invoice->chkby }}</a></th>
<th class="align-middle" scope="row">
@if ($invoice->isposted == false)
@php
echo 'Pending';
@endphp
@else
@php
echo 'Finished';
@endphp
@endif
</tr>
@endif
@endforeach
</tbody>
</table>
{{ $indexInvoices->links('pagination::bootstrap-4') }}
这是我的发票控制器:
public function searchDateInvoice(Request $request)
{
$fromDate = $request->get('dateFrom');
$toDate = $request->get('dateTo');
if(!empty($fromDate))
{
$searchDateInvoice = Invoices::whereBetween('saledate', [$fromDate, $toDate])
->orderby('saleno', 'desc')
->paginate(15);
$searchDateInvoice->appends(['dateFrom'=>$fromDate,'dateTo'=>$toDate]);
}
return view('invoices.searchdateinvoice')->with(['searchDateInvoice'=>$searchDateInvoice]);
}
这是我的路线 (web.php)
Route::get('/invoices','App\Http\Controllers\InvoiceController@indexInvoice');
Route::get('/searchInvoice','App\Http\Controllers\InvoiceController@searchInvoice')->name('searchInvoice');
Route::get('/searchdateinvoice','App\Http\Controllers\InvoiceController@searchDateInvoice')->name('searchdateinvoice');
【问题讨论】:
-
在 value="=date('Y-m-d')?>" 中使用这样的php日期函数希望能解决你的问题。编辑你能解释一下你想显示什么类型的数据吗
标签: javascript php html laravel