2017-08-03 205 views
0

我目前有這個代碼,現在我需要一些幫助,使其工作基於用戶選擇的內容。如何根據選定的值獲取數據以獲取excel?

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' 更換呢?如果我把直會有錯誤象下面這樣:

Type error: Too few arguments to function App\Http\Controllers\xxxx\xxxx\xxxx::App\Http\Controllers\xxx\xxxx{closure}(), 1 passed and exactly 2 expected

回答

0

我不知道你有你的對話表什麼字段名,但是......

$產品=對話框::在哪裏(」 eType',$ eType) - > get();

$產品=對話框::在哪裏( 'CLAIM_TYPE',$ ETYPE) - >獲得();

+0

eType是列名稱.. –