36 lines
919 B
PHP
36 lines
919 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Service;
|
|
use App\Models\Setting;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class ServiceImageResolver
|
|
{
|
|
public function keyVisualFor(Service $service): ?string
|
|
{
|
|
return $this->resolve($service->key_visual_filename, 'current_key_visual');
|
|
}
|
|
|
|
public function backgroundFor(Service $service): ?string
|
|
{
|
|
return $this->resolve($service->background_filename, 'current_background');
|
|
}
|
|
|
|
private function resolve(?string $serviceFilename, string $settingKey): ?string
|
|
{
|
|
if ($serviceFilename !== null && Storage::disk('public')->exists($serviceFilename)) {
|
|
return $serviceFilename;
|
|
}
|
|
|
|
$globalFilename = Setting::get($settingKey);
|
|
|
|
if ($globalFilename !== null && Storage::disk('public')->exists($globalFilename)) {
|
|
return $globalFilename;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|