【问题标题】:How to get data to excel based on selected value?如何根据所选值获取数据到excel?
【发布时间】:2018-01-10 11:27:44
【问题描述】:

我目前有此代码,现在我需要一些帮助才能根据用户选择的内容使其正常工作。

public function downloadResponse(Request $request)
{

    $inputs = $request->input();
    $eType = $inputs['chapter_category'];

    Excel::create('Export data', function($excel,$eType)
    {
        $excel->sheet('Sheet 1', function($sheet)
        {
            $products = Dialog::where('eType', 'claim_type')->get();;
            foreach($products as $product)
            {
                $data[] = array(
                    $product->eType,
                    $product->eVal,
                    $product->intent,
                    $product->reply,
                );
            }
            $sheet->fromArray($data, null, 'A1', false, false);
            $headings = array('Entity Type', 'Entity Value', 'Intent', 'Reply');
            $sheet->prependRow(1, $headings);
        });
    })->export('csv');

}

这条线我已经硬线了:

$products = Dialog::where('eType', 'claim_type')->get();

那么我如何获得$eType 并将其替换为'claim_type'?如果我直接输入会有如下错误:

类型错误:函数参数太少 App\Http\Controllers\xxxx\xxxx\xxxx::App\Http\Controllers\xxx\xxxx{closure}(), 1 个通过,恰好 2 个预期

【问题讨论】:

    标签: php excel laravel


    【解决方案1】:

    我不确定您的 Dialog 表中有哪些字段名称,但是...

    $products = Dialog::where('eType', $eType)->get();

    $products = Dialog::where('claim_type', $eType)->get();

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-29
      • 2016-03-20
      • 1970-01-01
      相关资源
      最近更新 更多