2024-05-27 21:08:09 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Form\Actions;
|
|
|
|
|
|
|
|
use App\Form\Models\Form;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
use League\Csv\Writer;
|
|
|
|
use Lorisleiva\Actions\ActionRequest;
|
|
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
|
|
|
|
|
|
class ExportAction
|
|
|
|
{
|
|
|
|
use AsAction;
|
|
|
|
|
|
|
|
public function handle(Form $form): string
|
|
|
|
{
|
2024-07-16 00:05:27 +02:00
|
|
|
return CreateExcelDocumentAction::run($form, $form->participants);
|
2024-05-27 21:08:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function asController(Form $form, ActionRequest $request): StreamedResponse
|
|
|
|
{
|
|
|
|
$contents = $this->handle($form);
|
|
|
|
|
2024-07-16 00:05:27 +02:00
|
|
|
$filename = 'tn-' . $form->slug . '.xlsx';
|
2024-05-27 21:08:09 +02:00
|
|
|
Storage::disk('temp')->put($filename, $contents);
|
|
|
|
|
|
|
|
return Storage::disk('temp')->download($filename);
|
|
|
|
}
|
|
|
|
}
|