「CSVエクスポート」ファイル名を動的に設定
All checks were successful
Deploy main / deploy (push) Successful in 22s

This commit is contained in:
kin.rinzen 2025-10-11 12:21:03 +09:00
parent 9a0f8a8846
commit c25833562c

View File

@ -196,18 +196,34 @@ class StationController extends Controller
}
/**
* CSVエクスポート
* CSVエクスポート(日本語ヘッダー付き)
*/
public function export()
{
return response()->streamDownload(function () {
// Excel用のUTF-8 BOM
echo "\xEF\xBB\xBF";
echo "station_id,station_neighbor_station,station_name_ruby,station_route_name,park_id,operator_id\n";
// ファイル名
$filename = '近傍駅マスタ_' . now()->format('YmdHis') . '.csv';
foreach (Station::all() as $station) {
echo "{$station->station_id},{$station->station_neighbor_station},{$station->station_name_ruby},{$station->station_route_name},{$station->park_id},{$station->operator_id}\n";
return response()->streamDownload(function () {
// Excel用 UTF-8 BOM
echo "\xEF\xBB\xBF";
// 日本語ヘッダー行
echo "近傍駅ID,駐車場ID,近傍駅,近傍駅ふりがな,路線名,近傍駅座標(緯度),近傍駅座標(経度)\n";
// データ行
foreach (\App\Models\Station::all() as $station) {
echo implode(',', [
$station->station_id,
$station->park_id,
$station->station_neighbor_station,
$station->station_name_ruby,
$station->station_route_name,
$station->station_latitude,
$station->station_longitude,
// $station->operator_id,
]) . "\n";
}
}, 'stations.csv');
}, $filename);
}
}