Я думаю, что я близок, мне просто нужно передать $ excelFile в Mail, но он продолжает говорить, что он неопределен, но когда я передаю $ truckstop_post, он проходит, но эти данные не отформатированы правильно, потому что он еще не прошел через Excel :: create. Как мне получить результат \ 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('mike@gmail.com')->subject('subject');
$message->from('mike@gmail.com', \Auth::user()->name);
$message->attachData($excelFile, 'Invoice.csv');
});});
return back()->with('status', 'You Posted Truckstop!');
}
Вот как будут выглядеть результаты, если я передам $ truckstop_post в attachData (), но, конечно, это не красиво отформатированный CSV-файл
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('example@gmail.com')
->subject('Email Subject Line');
$message->from('daniel@twbb.com', 'Daniel');
$message->attachData($excelFile, 'Invoice.csv');
});
return $excelFile;
}
Других решений пока нет …