在特定文件夹中导出带有 laravel excel 的 csv

Export csv with laravel excel in specific folder

您好,我正在尝试导出特定文件夹中的 csv 文件,我尝试了几种方法但没有结果

通过执行以下代码,它可以在默认 /app/ 文件夹中正常导出我

  public function export(){
    $super = Super::select('ano_plantacion','zona','sitio', 'manejo','sup_ha','codigo','rpend')->get();
    Excel::store(new SuperExport($super), 'Super.csv')); 
  }

我试试这个:

Excel::store(new SuperExport($super), 'Super.csv', storage_path('/app/export'));

错误:

"Trying to access array offset on value of type null"

还有这个:

Excel::store(new SuperExport($super), storage_path('/app/export/Super.csv'));

错误:

Impossible to create the root directory "C:\Users\pachi\Documents\Version_web\mpe_web\storage\app\C:/Users/pachi/Documents/Version_web/mpe_web/storage/app/export

请帮忙

由于 Excel store() 方法使用默认磁盘,如果您不指定另一个磁盘,默认情况下 laravel 指向 storage_path('app'),您可以只需将 export/ 目录添加到文件名前:

Excel::store( new SuperExport($super), '/export/Super.csv' );

或者,您可以通过在 /config/filesystems.php 文件的 'disks' 索引下添加以下数组来为导出创建磁盘:

'disks' => [
    // your other disks here, leave them as they are, and add this one

    'export' => [
        'driver' => 'local',
        'root' => storage_path('app/export'),
    ],

],

然后将该磁盘指定为 store() 方法的第三个参数:

Excel::store( new SuperExport($super), 'Super.csv', 'export' );