【问题标题】:Attach Excel File with Markdown Mail使用 Markdown 邮件附加 Excel 文件
【发布时间】:2017-04-10 18:11:02
【问题描述】:

我尝试在我的电子邮件中附加一个 excel 文件,但我收到一个错误:basename() 期望参数 1 是一个字符串。我在哪里做错了?非常感谢提前!!!!

这里是我的邮件类:

public function build()
    {

        $licencies = Licencies::where('lb_assurance' , '=' , 'Lafont')->where('created_at' , Carbon::today())->get();
        $excel_file = Excel::create('DailyRecapLicencesLafont', function($excel) use ($licencies) {
            $excel->sheet('Excel', function($sheet) use ($licencies) {
                $sheet->fromArray($licencies);
            });
        });

        return $this->markdown('email.licences.lafont')->attach($excel_file , 'excel.xls');
    }

【问题讨论】:

  • $excel_file 是一个对象,attach() 期望第一个参数是一个字符串,即被附加文件的路径
  • 感谢您的回答,您知道实现我想做的最好的方法吗?

标签: laravel


【解决方案1】:

试试这个:

public function build()
{

    $licencies = Licencies::where('lb_assurance' , '=' , 'Lafont')->where('created_at' , Carbon::today())->get();
    $excel_file = Excel::create('DailyRecapLicencesLafont', function($excel) use ($licencies) {
        $excel->sheet('Excel', function($sheet) use ($licencies) {
            $sheet->fromArray($licencies);
        });
    });

    return $this->markdown('email.licences.lafont')->attach($excel_file->store("xls",false,true)['full'], 'excel.xls');
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-17
    • 2017-10-23
    • 1970-01-01
    • 2014-05-09
    • 1970-01-01
    • 1970-01-01
    • 2014-10-10
    • 1970-01-01
    相关资源
    最近更新 更多