Overview
Dashboard Laravel uses Eloquent ORM, Laravel’s powerful database abstraction layer. Models represent database tables and define relationships between entities.All models are located in
app/Models/ and extend Illuminate\Database\Eloquent\ModelCore Models
The application includes 7 primary models representing the business domain:User
Authentication and user management
Cliente
Customer/client records with relationships
Venta
Sales transactions and orders
Factura
Invoice generation and tracking
Mensaje
Messaging system
Nosotros
About/company information
Home & Estadisticas
Dashboard statistics
User Model
Location:app/Models/User.php
Handles user authentication and authorization.
User Model Details
User Model Details
Extends:
Illuminate\Foundation\Auth\User as AuthenticatableTraits:HasFactory- Enables model factories for testingNotifiable- Adds notification capabilities
name- User’s full nameemail- User’s email addresspassword- Hashed password
password- Never exposed in JSON responsesremember_token- Session persistence token
email_verified_at- Automatically cast to DateTimepassword- Automatically hashed on save
Cliente Model
Location:app/Models/Cliente.php
Represents customers/clients with full relationship mapping.
Cliente Model Details
Cliente Model Details
Table:
clientesFillable Attributes:nombre- First nameapellido- Last nameemail- Contact emailtelefono- Phone numberestado- Client status (active/inactive)segmento- Customer segmenttotal_compras- Total purchase amount
hasMany(Venta::class)- One client has many saleshasMany(Factura::class)- One client has many invoiceshasMany(Mensaje::class)- One client has many messages
Venta Model
Location:app/Models/Venta.php
Tracks sales transactions and order information.
Venta Model Details
Venta Model Details
Table:
ventasFillable Attributes:numero_orden- Unique order numbercliente_id- Foreign key to Clienteproducto- Product/service descriptiontotal- Sale total amountestado- Order status (pending/completed/cancelled)
belongsTo(Cliente::class)- Each sale belongs to one clienthasOne(Factura::class)- Each sale has one invoice
Factura Model
Location:app/Models/Factura.php
Manages invoice generation and payment tracking.
Factura Model Details
Factura Model Details
Table:
facturasFillable Attributes:numero_factura- Invoice numbercliente_id- Foreign key to Clienteventa_id- Foreign key to Ventaconcepto- Invoice description/conceptmonto- Invoice amountfecha_emision- Issue datefecha_vencimiento- Due dateestado- Payment status (paid/pending/overdue)
fecha_emision- Cast to Carbon date instancefecha_vencimiento- Cast to Carbon date instance
belongsTo(Cliente::class)- Invoice belongs to clientbelongsTo(Venta::class)- Invoice belongs to sale
Mensaje Model
Location:app/Models/Mensaje.php
Handles customer messages and communications.
Mensaje Model Details
Mensaje Model Details
Table:
mensajesFillable Attributes:cliente_id- Foreign key to Clientecontenido- Message content/bodytipo- Message type (inquiry/support/feedback)leido- Read status
leido- Cast to boolean (true/false)
belongsTo(Cliente::class)- Message belongs to client
Additional Models
Nosotros Model
Nosotros Model
Location: Basic model for storing “About Us” company information. Uses default Eloquent behavior with timestamps enabled.
app/Models/Nosotros.phpHome & Estadisticas Models
Home & Estadisticas Models
Location:
app/Models/home.php and app/Models/estadisticas.phpSupport models for dashboard statistics and home page data aggregation.Model Relationships
Understanding the relationship structure:Relationship Types
hasMany
One-to-many relationship. Cliente has many Ventas, Facturas, and Mensajes.
belongsTo
Inverse of hasMany. Venta/Factura/Mensaje belong to Cliente.
hasOne
One-to-one relationship. Each Venta has one Factura.
Using Model Relationships
Accessing Related Data
Mass Assignment Protection
All models use the$fillable property for mass assignment protection:
Only attributes listed in
$fillable can be mass-assigned using create() or update() methods. This protects against mass assignment vulnerabilities.Timestamps
All models automatically track creation and modification times:created_at- Automatically set when record is createdupdated_at- Automatically updated when record is modified
Timestamps are enabled by default. Access them as Carbon instances for easy date manipulation.
Next Steps
Controllers
Learn how controllers interact with models
Database Migrations
View database schema definitions
