2017-01-20 2 views
1

私は近いと思いますが、メールで$ excelFileを渡す必要がありますが、未定義と言っていますが、$ truckstop_postを渡すとデータは正しくフォーマットされません。まだ。どのようにして\ Excel :: createの結果をMail :: sendに得るのですか?エクセルファイルを電子メールに添付するにはどうすればよいですか?

public function truckstopPost() 
{ 
    $type = 'csv'; 



    $truckstop_post = Loadlist::select('pick_city', 'pick_state', 'delivery_city', 'delivery_state', 'trailer_type', 'pick_date', 'load_type', 'length', 'width', 'height', 'weight', 'offer_money', 'special_instructions', 'company_contact', 'contact_phone')->where('urgency', 'OPEN')->orderBy('id', 'desc')->get(); 

    $excelFile = \Excel::create('itransys', function($excel) use ($truckstop_post) { 
     $excel->sheet('mySheet', function($sheet) use ($truckstop_post) 
     { 
      $sheet->fromArray($truckstop_post); 

     }); 


     $info = Load::find(8500); 

     $info = ['info'=>$info]; 


     Mail::send(['html'=>'email.invoice_email_body'], $info, function($message) use ($info, $excelFile){ 

     $message->to('[email protected]')->subject('subject'); 

     $message->from('[email protected]', \Auth::user()->name); 

     $message->attachData($excelFile, 'Invoice.csv'); 

     }); 


     }); 

    return back()->with('status', 'You Posted Truckstop!'); 

} 

これは)私がattachData(へ$ truckstop_postを渡した場合の結果がどのように見えるかであるが、当然のないきれいにフォーマットのCSVファイルのthats

enter image description here

+0

問題であり、正確には何?エクセルを生成しますか?メールに添付しますか? – Dekel

+0

メールに添付する方法、$ message-> attachData(???、 'Invoice.csv');次に何が起こるか - >ダウンロード($タイプ); – mcornille

+0

したがって、質問からファイルの添付ファイルに関連しないものはすべて削除してください。 Xというファイルがあり、そのファイルにアタッチしたいとします。 – Dekel

答えて

1
public function post() 
{ 
    $type = 'csv'; 

    $create_excel = List::select('pick_city', 'pick_state', 'delivery_city', 'delivery_state')->where('urgency', 'OPEN')->orderBy('id', 'desc')->get()->toArray(); 

    $excelFile = \Excel::create('itrans', function($excel) use ($create_excel) { 
     $excel->sheet('mySheet', function($sheet) use ($create_excel) 
     { 
      $sheet->fromArray($create_excel); 


     }); 

    })->download($type); 

    Mail::send(['html'=>'email.email_body'] function($message) { 

    $message->to('[email protected]') 

    ->subject('Email Subject Line'); 

    $message->from('[email protected]', 'Daniel'); 

    $message->attachData($excelFile, 'Invoice.csv'); 

}); 

    return $excelFile; 

} 
+0

私は自分の質問を更新しました。 – mcornille

+0

dd($ create_excel) – Paras

+0

の出力を初期化した行の後、\ Excel :: createを呼び出す前にdd($ create_excel)することができますか? – Paras

関連する問題