69 lines
1.3 KiB
PHP
Executable File
69 lines
1.3 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Mensaje extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'mensajes';
|
|
|
|
protected $fillable = [
|
|
'nombre',
|
|
'email',
|
|
'telefono',
|
|
'mensaje',
|
|
'leido',
|
|
];
|
|
|
|
protected $casts = [
|
|
'leido' => 'boolean',
|
|
'created_at' => 'datetime',
|
|
'updated_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* Scope para filtrar mensajes no leídos
|
|
*/
|
|
public function scopeNoLeidos(Builder $query): Builder
|
|
{
|
|
return $query->where('leido', false);
|
|
}
|
|
|
|
/**
|
|
* Marcar mensaje como leído
|
|
*/
|
|
public function marcarLeido(): bool
|
|
{
|
|
return $this->update(['leido' => true]);
|
|
}
|
|
|
|
/**
|
|
* Marcar mensaje como no leído
|
|
*/
|
|
public function marcarNoLeido(): bool
|
|
{
|
|
return $this->update(['leido' => false]);
|
|
}
|
|
|
|
/**
|
|
* Obtener iniciales del nombre
|
|
*/
|
|
public function getInicialesAttribute(): string
|
|
{
|
|
$nombres = explode(' ', $this->nombre);
|
|
$iniciales = '';
|
|
foreach ($nombres as $nombre) {
|
|
if (! empty($nombre)) {
|
|
$iniciales .= strtoupper($nombre[0]);
|
|
}
|
|
}
|
|
|
|
return $iniciales;
|
|
}
|
|
}
|