laravel-vuexy-contacts/Services/ContactableItemService.php
2025-03-05 21:11:33 -06:00

49 lines
1.1 KiB
PHP

<?php
namespace Koneko\VuexyContacts\Services;
use Koneko\VuexyAdmin\Models\Setting;
class ContactableItemService
{
protected $settingsKey = 'contactable_item_types';
/**
* Obtiene la lista de tipos de medios de contacto desde settings.
*
* @return array
*/
public function getContactableTypes(): array
{
$setting = Setting::where('key', $this->settingsKey)->first();
return $setting ? json_decode($setting->value, true) : [];
}
/**
* Guarda una lista de tipos de medios de contacto.
*
* @param array $types
* @return bool
*/
public function saveContactableTypes(array $types): bool
{
return Setting::updateOrCreate(
['key' => $this->settingsKey],
['value' => json_encode($types)]
) ? true : false;
}
/**
* Obtiene un tipo de contacto específico por ID.
*
* @param int $id
* @return array|null
*/
public function getTypeById(int $id): ?array
{
$types = $this->getContactableTypes();
return collect($types)->firstWhere('id', $id);
}
}