You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.0 KiB
39 lines
1.0 KiB
<?php
|
|
|
|
namespace App\Domains\System\Actions\Settings;
|
|
|
|
use App\Domains\System\DTOs\SystemSetingDTO;
|
|
use App\Domains\System\Models\SystemSettings;
|
|
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
|
|
|
class UpdateSettings
|
|
{
|
|
public function execute(SystemSetingDTO $dto): void
|
|
{
|
|
$value = $dto->value;
|
|
$schema = $dto->key->getSchema();
|
|
|
|
if ($schema->type->isFile()) {
|
|
$currentSettings = SystemSettings::where('key', $dto->key->value)->value('value');
|
|
|
|
if ($currentSettings) {
|
|
remove_file($currentSettings);
|
|
}
|
|
|
|
if ($value instanceof TemporaryUploadedFile) {
|
|
$value = upload_file(
|
|
file: $value,
|
|
path: '/system/settings/'.$dto->key->value,
|
|
disk: 'public'
|
|
);
|
|
}
|
|
}
|
|
|
|
SystemSettings::updateOrCreate(
|
|
['key' => $dto->key->value],
|
|
['value' => $value],
|
|
);
|
|
|
|
cache()->forget(SystemSettings::$cacheName);
|
|
}
|
|
}
|
|
|