首页 > 解决方案 > 单击导出 excel 按钮时如何传递链接参数?

问题描述

我需要帮助才能在 URL 上传递参数。

路由.php

Route::get('downloadExcel/{type}', 'ExcelController@downloadExcel');

刀片.php

<a href="{{ URL::to('/downloadExcel/xls') }}" class="btn btn-warning btn-sm hidden-print"><i class="glyphicon glyphicon-export"></i> Export to Excel</a>

控制器

class ExcelController extends Controller{
    public function downloadExcel($type, Request $request)
    {
     return Excel::create('Laporan Kehadiran Harian', function($excel) use 
      ($transaksi) {
            $excel->sheet('mySheet', function($sheet) use ($transaksi)
            {
                $sheet->fromArray($transaksi);
            });
        })->download($type);
    }
}

标签: phplaravel

解决方案


在blade.php 中尝试将第二个参数设置为具有type属性和要传递的值的数组。

如果它是“xls”,它将是以下内容:

<a href="{{ URL::to('/downloadExcel', array("type" => "xls")) }}"></a>

推荐阅读