Skip to content

Commit

Permalink
Abstract csv download inside Response macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehedi Hassan authored and Mehedi Hassan committed Aug 3, 2017
1 parent dec0d48 commit b5b5917
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 8 additions & 0 deletions Modules/Core/macros.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,11 @@

return new HtmlString($string);
});

Response::macro('csv', function ($file, $filename, $status = 200, $headers = []) {
return response($file, $status, array_merge([
'Content-Type' => 'application/csv',
'Content-Disposition' => "attachment; filename={$filename}",
'Pragma' => 'no-cache',
], $headers));
});
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ public function update(TranslationTranslation $translationTranslation, Request $

public function export(TranslationsExporter $exporter)
{
return response()->make($exporter->export(), 200, [
'Content-Type' => 'application/csv',
'Content-Disposition' => "attachment; filename={$exporter->getFileName()}",
'Pragma' => 'no-cache',
]);
return response()->csv($exporter->export(), $exporter->getFileName());
}

public function import(ImportTranslationsRequest $request, TranslationsImporter $importer)
Expand Down

0 comments on commit b5b5917

Please sign in to comment.