The Mensaje model represents messages or communications in the Dashboard Laravel application. Each message is associated with a customer and includes read/unread status tracking with automatic boolean casting.
The Mensaje model is ideal for customer communication tracking, support tickets, or notification systems with read status management.
use App\Models\Mensaje;$mensaje = Mensaje::create([ 'cliente_id' => 1, 'contenido' => '¿Cuál es el estado de mi pedido #ORD-2026-001?', 'tipo' => 'consulta', 'leido' => false,]);
// Get all unread messages$mensajesNoLeidos = Mensaje::where('leido', false)->get();// Get unread messages with customer info$mensajesPendientes = Mensaje::with('cliente') ->where('leido', false) ->orderBy('created_at', 'desc') ->get();// Get messages by type$consultas = Mensaje::where('tipo', 'consulta')->get();$soportes = Mensaje::where('tipo', 'soporte') ->where('leido', false) ->get();// Get messages for specific customer$mensajesCliente = Mensaje::where('cliente_id', 1) ->orderBy('created_at', 'desc') ->get();
// Mark single message as read$mensaje = Mensaje::find(1);$mensaje->update(['leido' => true]);// Mark all messages from a customer as readMensaje::where('cliente_id', 1) ->where('leido', false) ->update(['leido' => true]);// Mark all unread messages older than 7 days as readMensaje::where('leido', false) ->where('created_at', '<', now()->subDays(7)) ->update(['leido' => true]);