first commit
This commit is contained in:
48
Services/ContactableItemService.php
Normal file
48
Services/ContactableItemService.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user