您可以使用store 方法将文件存储在文件系统中。
来自docs:
导出可以轻松存储在 Laravel 支持的任何文件系统上。
默认磁盘
public function storeExcel()
{
// Store on default disk
Excel::store(new InvoicesExport(2018), 'invoices.xlsx');
}
自定义磁盘
public function storeExcel()
{
// Store on a different disk (e.g. s3)
Excel::store(new InvoicesExport(2018), 'invoices.xlsx', 's3');
// Store on a different disk with a defined writer type.
Excel::store(new InvoicesExport(2018), 'invoices.xlsx', 's3', Excel::XLSX);
}
现在理想情况下,您应该将文件存储在 storage/app/public/uploads/release 中,并按照 here 的说明创建从 public/storage/ 到 storage/app/public 的符号链接。
但如果您真的想将其存储在public/uploads/release 中,您可以在config/filesystems.php 中创建新的自定义磁盘。比如:
'real_public' => [
'driver' => 'local',
'root' => public_path(),
'url' => env('APP_URL'),
'visibility' => 'public',
],
然后你可以使用自定义磁盘来存储文件:
public function export_release()
{
Excel::store(new ReleaseExportView(), 'uploads/release/release.xlsx', 'real_public');
}