【发布时间】:2020-05-13 01:24:49
【问题描述】:
当日期为空时,我尝试让我的报告显示“全部”而不是默认日期值“{ 01-Jan-1970 / 01-Jan-1970 }”,我在这里阅读了其他类似案例并尝试过解决方案,但对我不起作用 我在这里使用日期而不是日期时间,而我的 $from 和 $to 只是一个字段而不是我数据库中列的一部分,我只是用它来过滤我之前的报告
StockinController.php
public function print(Request $req)
{
$method = $req->method();
if ($req->isMethod('post'))
{
$from = $req->input('from');
$to = $req->input('to');
$start_date = date('d-M-Y', strtotime($from));
$end_date = date('d-M-Y', strtotime($to));
if ($req->has('search'))
{
if ($from && $to != null) {
$search = \App\Stockin::whereBetween('tanggal',[$from,$to])->get();
return view('transaction.stockin.stockinform',['data_stockin' => $search]);
}
else
{
$data_stockin = \App\Stockin::all();
return view('transaction.stockin.stockinform',['data_stockin' => $data_stockin]);
}
}
elseif ($req->has('exportPDF'))
{
if ($from && $to != null) {
$PDFReport = \App\Stockin::whereBetween('tanggal',[$from,$to])->get();
$pdf = PDF::loadView('transaction.stockin.stockin_pdf', ['data_stockin' => $PDFReport,'from' => $start_date, 'to' => $end_date])->setPaper('a4');
return $pdf->stream();
}
else
{
$PDFReport = \App\Stockin::all();
$pdf = PDF::loadView('transaction.stockin.stockin_pdf', ['data_stockin' => $PDFReport,'from' => $start_date, 'to' => $end_date])->setPaper('a4');
return $pdf->stream();
}
}
}
}
stockin_pdf.blade.php
<center>
<h5>STOCK-IN REPORT</h5>
<hr>
@if($from && $to != null) {
<small>{{$from}} / {{$to}} </small>
}
@else {
<small>All</small>
}
@endif
</center>
提前谢谢你:)
【问题讨论】:
标签: laravel date datetime if-statement report