Skip to content

Commit cc738ba

Browse files
committed
Merge branch 'staging'
2 parents 552623d + 26cb48a commit cc738ba

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [1.3.0] - 2025-06-30
8+
9+
_Stable release based on [1.3.0-rc.1]._
10+
11+
## [1.3.0-rc.1] - 2025-06-30
12+
13+
### Changed
14+
15+
- Generate semantic export name.
16+
717
## [1.2.0] - 2025-06-20
818

919
_Stable release based on [1.2.0-rc.1]._
@@ -363,6 +373,8 @@ _Stable release based on [0.1.0-rc.1]._
363373

364374
- New changelog file.
365375

376+
[1.3.0]: https://https://github.com/internetguru/laravel-model-browser/compare/v1.2.0...v1.3.0
377+
[1.3.0-rc.1]: https://github.com/internetguru/laravel-model-browser/releases/tag/v1.2.0
366378
[1.2.0]: https://https://github.com/internetguru/laravel-model-browser/compare/v1.1.2...v1.2.0
367379
[1.2.0-rc.1]: https://github.com/internetguru/laravel-model-browser/releases/tag/v1.1.2
368380
[1.1.2]: https://https://github.com/internetguru/laravel-model-browser/compare/v1.1.1...v1.1.2

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.0
1+
1.3.0

src/Components/BaseModelBrowser.php

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ public function downloadCsv(): StreamedResponse
138138
$headers = array_values($this->viewAttributes);
139139
$handle = fopen('php://memory', 'w+');
140140

141-
// Write data to the memory stream
142141
fputcsv($handle, $headers);
143142
foreach ($data as $item) {
144143
$row = [];
@@ -148,15 +147,45 @@ public function downloadCsv(): StreamedResponse
148147
fputcsv($handle, $row);
149148
}
150149

151-
// Rewind the memory stream to the beginning and capture the CSV content
152150
rewind($handle);
153151
$csvContent = stream_get_contents($handle);
154152
fclose($handle);
155153

156-
// Stream the CSV content as a download
154+
$exportName = $this->generateExportFilename();
155+
157156
return response()->streamDownload(function () use ($csvContent) {
158157
echo $csvContent;
159-
}, 'data.csv', ['Content-Type' => 'text/csv']);
158+
}, $exportName, ['Content-Type' => 'text/csv']);
159+
}
160+
161+
protected function generateExportFilename(): string
162+
{
163+
$modelName = class_basename($this->model);
164+
$fileName = $modelName;
165+
166+
if (!empty($this->filter)) {
167+
$filterInfo = $this->filterColumn !== 'all'
168+
? "{$this->filterColumn}-{$this->filter}"
169+
: "filter-{$this->filter}";
170+
171+
$filterInfo = preg_replace('/[^a-zA-Z0-9_-]/', '_', $filterInfo);
172+
$fileName .= "-{$filterInfo}";
173+
}
174+
175+
if (!empty($this->sort)) {
176+
$sortInfo = [];
177+
foreach ($this->sort as $column => $direction) {
178+
$sortInfo[] = "{$column}-{$direction}";
179+
}
180+
if (!empty($sortInfo)) {
181+
$fileName .= "-sort-" . implode('-', $sortInfo);
182+
}
183+
}
184+
185+
$fileName .= "-" . date('Y-m-d');
186+
$fileName = preg_replace('/[^a-zA-Z0-9_-]/', '_', $fileName);
187+
188+
return "{$fileName}.csv";
160189
}
161190

162191
protected function getData(bool $paginate = true, bool $highlightMatches = true, bool $applyFormats = true)

0 commit comments

Comments
 (0)