folder($media); } public function getPathForConversions(Media $media): string { return $this->folder($media, 'conversations'); } public function getPathForResponsiveImages(Media $media): string { return $this->folder($media, 'responsive-images'); } /** * The folder shared by everything belonging to the given media. * * The fallback hands back the row's key as it comes, an integer, and lets * the declared return type do the widening. A media row without a key * therefore fails here rather than filing itself under an empty name, * which is the behaviour that has always been in place. */ protected function getBasePath(Media $media): string { return match ($media->model_type) { ModelIdentityMap::INVOICE_ALIAS => 'Invoices', ModelIdentityMap::ESTIMATE_ALIAS => 'Estimates', ModelIdentityMap::PAYMENT_ALIAS => 'Payments', default => $media->getKey(), }; } /** * That folder, or one named sub-folder of it, closed off with the * separator the media library expects to find at the end. */ private function folder(Media $media, ?string $subFolder = null): string { $path = $this->getBasePath($media).'/'; return $subFolder === null ? $path : $path.$subFolder.'/'; } }