Saving PDF's to their correct location

This commit is contained in:
David Bomba 2019-08-30 07:44:22 +10:00
parent 10272a1eeb
commit e4f33b06ba
2 changed files with 22 additions and 18 deletions

View File

@ -49,8 +49,8 @@ class QueryLogging
$time = $timeEnd - $timeStart; $time = $timeEnd - $timeStart;
//Log::info($request->method() . ' - ' . $request->url() . ": $count queries - " . $time); //Log::info($request->method() . ' - ' . $request->url() . ": $count queries - " . $time);
if($count > 16) // if($count > 16)
Log::info($queries); // Log::info($queries);
} }
} }

View File

@ -41,36 +41,40 @@ class CreateInvoicePdf
$invoice = $event->invoice; $invoice = $event->invoice;
$path = 'public/' . $invoice->client->client_hash . '/invoices/'; $path = 'public/' . $invoice->client->client_hash . '/invoices/';
$file = $path . $invoice->invoice_number . '.pdf'; $file_path = $path . $invoice->invoice_number . '.pdf';
Log::error($file);
//get invoice template
//get invoice design
$html = $this->generateInvoiceHtml($invoice->design(), $invoice); $html = $this->generateInvoiceHtml($invoice->design(), $invoice);
//todo - move this to the client creation stage so we don't keep hitting this unnecessarily //todo - move this to the client creation stage so we don't keep hitting this unnecessarily
Storage::makeDirectory($path, 0755); Storage::makeDirectory($path, 0755);
//create pdf //create pdf
$pdf = $this->makePdf(null,null,$html, $file); $pdf = $this->makePdf(null,null,$html);
// $path = Storage::putFile($file, $pdf); $path = Storage::put($file_path, $pdf);
//store pdf
//$path = Storage::putFile('public/' . $path, $this->file);
//$url = Storage::url($path);
} }
/**
private function makePdf($header, $footer, $html, $pdf) * Returns a PDF stream
*
* @param string $header Header to be included in PDF
* @param string $footer Footer to be included in PDF
* @param string $html The HTML object to be converted into PDF
*
* @return string The PDF string
*/
private function makePdf($header, $footer, $html)
{ {
return Browsershot::html($html) return Browsershot::html($html)
//->showBrowserHeaderAndFooter() //->showBrowserHeaderAndFooter()
//->headerHtml($header) //->headerHtml($header)
//->footerHtml($footer) //->footerHtml($footer)
->waitUntilNetworkIdle() ->waitUntilNetworkIdle()->pdf();
//->margins(10,10,10,10) //->margins(10,10,10,10)
->savePdf('test.pdf'); //->savePdf('test.pdf');
} }
/** /**
@ -79,15 +83,15 @@ class CreateInvoicePdf
* *
* @param string $design either the path to the design template, OR the full design template string * @param string $design either the path to the design template, OR the full design template string
* @param Collection $invoice The invoice object * @param Collection $invoice The invoice object
*
* @return string The invoice string in HTML format * @return string The invoice string in HTML format
*/ */
private function generateInvoiceHtml($design, $invoice) :string private function generateInvoiceHtml($design, $invoice) :string
{ {
//swap labels
$data['invoice'] = $invoice; $data['invoice'] = $invoice;
return view($design, $data)->render(); return view($design, $data)->render();
//return view('pdf.stub', $html)->render();
} }
} }