invoices = $invoices; $this->company = $company; $this->email = $email; $this->settings = $company->settings; } /** * Execute the job. * * * @return void * @throws \ZipStream\Exception\FileNotFoundException * @throws \ZipStream\Exception\FileNotReadableException * @throws \ZipStream\Exception\OverflowException */ public function handle() { $tempStream = fopen('php://memory', 'w+'); $options = new Archive(); $options->setOutputStream($tempStream); // create a new zipstream object $file_name = date('Y-m-d').'_'.str_replace(' ', '_', trans('texts.invoices')).'.zip'; $path = $this->invoices->first()->client->invoice_filepath(); $zip = new ZipStream($file_name, $options); foreach ($this->invoices as $invoice) { $zip->addFileFromPath(basename($invoice->pdf_file_path()), TempFile::path($invoice->pdf_file_path())); } $zip->finish(); Storage::disk(config('filesystems.default'))->put($path.$file_name, $tempStream); fclose($tempStream); $this->setMailDriver(); Mail::to($this->email) ->send(new DownloadInvoices(Storage::disk(config('filesystems.default'))->url($path.$file_name), $this->company)); UnlinkFile::dispatch(config('filesystems.default'), $path.$file_name)->delay(now()->addHours(1)); } }