57 lines
1.2 KiB
PHP
57 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Koneko\VuexyAdmin\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Koneko\VuexyAdmin\Services\ContactableItemService;
|
|
|
|
class ContactableItem extends Model
|
|
{
|
|
protected $table = 'contactable_items';
|
|
|
|
protected $fillable = [
|
|
'contactable_id',
|
|
'contactable_type',
|
|
'type',
|
|
'data_contact',
|
|
'preference_level',
|
|
'notes'
|
|
];
|
|
|
|
protected $casts = [
|
|
'preference_level' => 'integer',
|
|
];
|
|
|
|
/**
|
|
* Relación polimórfica con cualquier modelo (User, Empresa, etc.)
|
|
*/
|
|
public function contactable()
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
|
|
/**
|
|
* Devuelve la información del tipo de contacto desde `settings`
|
|
*/
|
|
public function getTypeInfoAttribute()
|
|
{
|
|
return app(ContactableItemService::class)->getTypeById($this->type);
|
|
}
|
|
|
|
/**
|
|
* Devuelve el nombre del tipo de contacto
|
|
*/
|
|
public function getTypeTextAttribute()
|
|
{
|
|
return $this->type_info['label'] ?? 'Desconocido';
|
|
}
|
|
|
|
/**
|
|
* Devuelve el icono del tipo de contacto
|
|
*/
|
|
public function getTypeIconAttribute()
|
|
{
|
|
return $this->type_info['icon'] ?? 'ti-help-circle';
|
|
}
|
|
}
|