私はそれが好きでした:$ tablesArray配列の
<?php
$tablesArray= [ // array of tables to export
'settings',
'groups',
'users',
];
$now_label= '_1';//strftime('%Y-%m-%d_%H_%M_%S');
$directories= [ public_path('uploads'), public_path('uploads/csv') , public_path('uploads/csv/loan_dump_'.$now_label) ];// to which directory export files
foreach($tablesArray as $next_key=>$next_table_name) { // all tables
$columnListing= \Schema::getColumnListing($next_table_name); // table columns
if ($next_table_name == 'settings') {
$dataRows = Settings::all();
}
if ($next_table_name == 'groups') {
$dataRows = Group::all();
}
if ($next_table_name == 'users') {
$dataRows = User::all();
}
if ($dataRows == null) {
die("-1 XXZ INVALID DATA");
}
$dataRowsArray = $dataRows->toArray();
$writeRowsArray= [];
$row= 0;
foreach($dataRowsArray as $next_key=>$nextDataRow) {
if (!empty($nextDataRow['created_at'])) {
$nextDataRow['created_at'] = $this->dateTimeToDbFormat($nextDataRow['created_at']);
}
if (!empty($nextDataRow['updated_at'])) {
$nextDataRow['updated_at'] = $this->dateTimeToDbFormat($nextDataRow['updated_at']);
}
if ($row == 0) { // first row with keys/file headers
$writeRowsArray[] = $nextDataRow;
} else {
$writeRowsArray[] = array_values($nextDataRow);
}
$row++;
}
$this->writeArrayToCsvFile($writeRowsArray, $next_table_name, $directories);
} // foreach($tablesArray as $next_key=>$next_table_name) { // all tables
public function writeArrayToCsvFile(array $dataArray, string $filename, array $directoriesArray) : int
{
self::createDir( $directoriesArray );
$path = $directoriesArray[count($directoriesArray)-1];
Excel::create($filename, function($excel) use($dataArray) {
$excel->sheet('file', function($sheet) use($dataArray) {
$sheet->fromArray($dataArray);
});
})->store('csv', $path)->export('csv');
return 1;
}
?>
のみ第一のファイルは、[OK]エクスポートされます。 最初のテーブルをコメントする場合は、次のテーブルがアップロードされます。
奇妙なファイルは何かが$ディレクトリのパスと "ダウンロード"ディレクトリ(私はkubuntuの下にあります)に2回アップロードされています。
あなたも、ループからのアップロードを処理するコードをあなたのコードを共有することができます –