Commit be564368 authored by Maik Messerschmidt's avatar Maik Messerschmidt
Browse files

Added route to download data as zip.

parent 4a45795c
......@@ -12,6 +12,8 @@ use Illuminate\Http\Request;
use Str;
use Log;
use Zip;
class ResultController extends Controller
{
/**
......@@ -138,6 +140,17 @@ class ResultController extends Controller
return $csv->getContent();
}
public function downloadZip() {
$zip = Zip::create("results.zip");
Result::all()->each(function($result) use ($zip) {
$filename = $result->created_at . ".json";
$zip->addRaw($result->getOriginal("data"), $filename);
});
return $zip;
}
/**
* Display the result as json.
*/
......
......@@ -57,6 +57,7 @@
</tbody>
</table>
<a href="{{ route('results.show-all-csv') }}">Download all results as CSV</a>
<a href="{{ route('results.show-all-csv') }}">Download all results as CSV</a> |
<a href="{{ route('results.download-zip') }}">Download all results as Zip</a>
@endsection
......@@ -25,6 +25,9 @@ Route::middleware(['web', 'auth'])->group(function() {
Route::get('/admin/results/show-all-csv', 'ResultController@showAllCSV')
->name('results.show-all-csv');
Route::get('/admin/results/download-zip', 'ResultController@downloadZip')
->name('results.download-zip');
Route::get('/admin/results/partial', 'ResultController@indexPartial')
->name('results.index.partial');
Route::resource('/admin/results', 'ResultController');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment