first commit
This commit is contained in:
56
Models/ContactableItem.PHP
Normal file
56
Models/ContactableItem.PHP
Normal file
@ -0,0 +1,56 @@
|
||||
<?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';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user