存储文件到S3无法转换为字符串

时间:2017-06-21 08:19:16

标签: laravel

我尝试将此文件存储到S3

时出现异常
  

类Maatwebsite \ Excel \ Writers \ LaravelExcelWriter的对象不能   被转换为字符串

这是我的代码:

$file = Excel::create('' . $date . '' , function($excel) use ($licencies) {
        $excel->sheet('Excel', function($sheet) use ($licencies)
        {
            $sheet->fromArray($licencies);

        });

    });

    Storage::disk('s3')->put($file , 'upload');

});

1 个答案:

答案 0 :(得分:2)

    $fileName = $date . '.xls';

    $fileContent = Excel::create($fileName , function($excel) use ($licencies) {
        $excel->sheet('Excel', function($sheet) use ($licencies) {
            $sheet->fromArray($licencies);
        });
    })->string('xls');

    Storage::disk('s3')->put($fileName, $fileContent);