HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/fire-tech/fire-tech.nl/app/KommaApp/Kms/Transfer/TransferService.php
<?php


namespace App\KommaApp\Kms\Transfer;


use App\KommaApp\Kms\Core\Sections\SectionService;
use App\KommaApp\Subscription\Kms\Transfer\SubscriptionCsvExportService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\HttpFoundation\StreamedResponse;

/**
 * Class ImportExportService
 *
 * Directs Import and Export services to do their job.
 * And is responsible for loading and offering files for download
 *
 * @package App\KommaApp\Kms\Transfer
 */
class TransferService extends SectionService
{
    protected $sortable = true;

    /** @var $exportService AbstractCsvExportService */
    protected $exportService;

    /**
     * @var string The name of the file input field
     */
    public static $fileInputFieldName = 'File-file';

    /**
     * TransferService constructor.
     *
     * @param SubscriptionCsvExportService $exportService
     */
    public function __construct(SubscriptionCsvExportService $exportService)
    {
        if(self::$fileInputFieldName == '')
            throw new \RuntimeException('Please set the static $inputFieldName variable to the input field name the transfer service should import files from');

        $this->forModelName = null;
        $this->exportService = $exportService;
    }

    public function export(Request $request):StreamedResponse
    {
        $path = 'inschrijvingen.csv';
        Storage::delete($path); //Delete old file if it exists.
        $csvData = $this->exportService->exportToCsvFileString($request->courseId, $request->dateNumber);
        Storage::put($path, $csvData);
        return Storage::download($path);
    }
}