file = $file; $this->costUnit = $costUnit; } public function saveUploadedFile() : ?InvoiceFile { try { $directory = sprintf( '%1$s/invoices/%2$s', app('tenant')->slug, $this->costUnit->id ); $filename = $this->normalizeFilename($this->file->getClientOriginalName()); $path = $this->file->storeAs( $directory, $filename ); $invoiceFile = new InvoiceFile(); $invoiceFile->filename = $filename; $invoiceFile->fullPath = $path; return $invoiceFile; } catch (\Exception $e) { return null; } } private function normalizeFilename(string $filename) : string { return strtolower($filename) |> function (string $filename) : string { return str_replace(' ', '_', $filename); } |> function (string $filename) : string { return str_replace('ä', 'ae', $filename); } |> function (string $filename) : string { return str_replace('ö', 'oe', $filename); } |> function (string $filename) : string { return str_replace('ü', 'ue', $filename); } |> function (string $filename) : string { return str_replace('ß', 'ss', $filename); }; } }