orders()->first()->customer_po ?? ''; $firstOrderPo = preg_replace('/[\\\\\/:*?"<>|]/', '', $firstOrderPo); // Remove invalid characters $firstOrderPo = str_replace(' ', '-', $firstOrderPo); $url = strtolower($invoice->internal_id.'-'.$invoice->customer->company_name.'-'.$firstOrderPo.'.pdf'); Pdf::view('pdf.invoice', ['invoice' => $invoice]) ->withBrowsershot(function (Browsershot $browsershot) { $browsershot->noSandbox(); }) ->margins(8, 8, 15, 8) ->footerView('pdf.invoice-footer', ['invoice' => $invoice]) ->save($url); return redirect($url); } }