下载并邮寄 Excel 文件 Laravel

Download And Mail Excel File Laravel

我有一个充满用户的数据库,在后端我有一个按钮可以收集我的数据库并将其下载为 Excel 文件。 (使用 Maat 网站)。同时,我希望管理员收到一封包含此 Excel 文件的电子邮件。如何将此字段添加到电子邮件中? 这是代码:

public function excel()
{
    Excel::create('Participants', function($excel) {

        $excel->sheet('Participants', function($sheet) {

            $sheet->fromArray(Participant::where('enabled',1)->get(), null, 'A1', false, false);

        });
    })->download("xlsx");
    Mail::raw("In attachment excelfile of participants ", function($message)
    {
        $message->subject('ExcelFile Participants!');
        $message->from('no-reply@asadventurecontest.be', 'As Adventure Contest');
        $message->to('admin@mywebsite.com');
        //$message->attachData(, 'Participants.xlsx');
    });
}

我认为你应该存储你的 Excel 文件并附在你的邮件中 cf. Laravel Documentation。 要存储您的 Excel,您可以使用函数 'store':Laravel Excel Store.

之后,您可以删除它或保留它。