首页 > 解决方案 > LARAVEL::如何在另一个刀片页面上显示请求的日期范围

问题描述

我有从我的刀片表单请求的功能start dateEnd date然后它从该日期范围下载报告

所以我想在第二页的顶部start date显示这些日期范围。End date

控制器

       public function stockIssued(Request $request) {

    $startdate=$request->startdate;
   $enddate=$request->enddate;
    //issued
   $stockIssued=DB::select(DB::raw(" SELECT 
    products.id, 
    products.name,  
    (select ifnull(sum(loadings.qty),0) from loadings where loadings.pid=products.id and 
              DATE(loadings.created_at)  BETWEEN STR_TO_DATE('$startdate','%m/%d/%Y') AND 
              STR_TO_DATE('$enddate','%m/%d/%Y')  ) as total_loadings_specific_date
    from products"));

$pdf = PDF::loadView('report.issuedreportprint',compact('stockIssued'));

return $pdf->download('issuedreport.pdf'); 
// return view('report.issuedreport',compact('stockIssued'));
//
  }

刀片视图(我想在报告顶部显示这些日期)

     </head>
     <body>
    <?php
    $startdate = $request->old('startdate');
      $enddate = $request->old('enddate');

      echo "<p>From:'$startdate'  To:'$enddate'</p>"

  ?>
 <table  width="90%" border="1"  align="center" style="margin-top: 20px;margin-bottom: 2px; margin- 
   left:10px; margin-right:10px; " >

  <thead>
    <tr>
      <th>Items Name</th>
      <th>Total Qty</th>
     </tr>
  </thead>
  <tbody>
    @foreach($stockIssued as $dt)
    <tr>
      <td>{{$dt->name}}</td>
      <td>{{$dt->total_loadings_specific_date ??0 }}</td>
      </tr>
    @endforeach
  </tbody>
</table>

    </body>
</html>

标签: phplaravel

解决方案


根据我的理解,您想将日期传递给您正在生成的 pdf 文件,您可以这样做:

$startdate = $request->startdate;
$enddate = $request->enddate;

$pdf = PDF::loadView('report.issuedreportprint',compact('stockIssued', 'startdate', 'enddate'));

然后在刀片文件中你可以直接访问它:

<p> From:{{ $startdate }}  To: {{ $enddate }} </p>

推荐阅读