Initial commit: Lash Vanshy - Complete project with admin panel, gallery, products, and contact
This commit is contained in:
68
app/Models/Mensaje.php
Executable file
68
app/Models/Mensaje.php
Executable file
@@ -0,0 +1,68 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user