. */ namespace App\Http\Controllers\Import; use App\Http\Controllers\Controller; use App\Services\CSV\Configuration\Configuration; use App\Services\Session\Constants; use App\Services\Storage\StorageService; use Illuminate\Contracts\Routing\ResponseFactory; use Illuminate\Http\Response; /** * Class DownloadController */ class DownloadController extends Controller { /** * @return ResponseFactory|Response */ public function download() { // do something $configuration = Configuration::fromArray(session()->get(Constants::CONFIGURATION)); // append the config file with values from the disk: $diskArray = json_decode(StorageService::getContent(session()->get(Constants::UPLOAD_CONFIG_FILE)), true, JSON_THROW_ON_ERROR); $diskConfig = Configuration::fromArray($diskArray); $configuration->setRoles($diskConfig->getRoles()); $configuration->setMapping($diskConfig->getMapping()); $configuration->setDoMapping($diskConfig->getDoMapping()); $array = $configuration->toArray(); $result = json_encode($array, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT, 512); $response = response($result); $name = sprintf('import_config_%s.json', date('Y-m-d')); $response->header('Content-disposition', 'attachment; filename=' . $name) ->header('Content-Type', 'application/json') ->header('Content-Description', 'File Transfer') ->header('Connection', 'Keep-Alive') ->header('Expires', '0') ->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0') ->header('Pragma', 'public') ->header('Content-Length', strlen($result)); return $response; } }