Skip to main content

Overview

The Employees API allows you to manage employee records within your organization. Employees are authenticated users with specific roles (cargos) and department assignments (dependencias). This API handles CRUD operations, authentication, status management, and various filtering capabilities.

The Employee Object

id_empleado
integer
Unique identifier for the employee
nombre
string
Employee’s first name (max 120 characters)
apellido
string
Employee’s last name (max 120 characters)
email
string
Employee’s email address (max 150 characters, must be unique)
telefono
string
Employee’s phone number (max 30 characters)
id_cargo
integer
Foreign key reference to the employee’s position/role
id_dependencia
integer
Foreign key reference to the employee’s department
estado
boolean
Employee’s active status (true = active, false = inactive)
cargo
object
Related position object with details about the employee’s role
dependencia
object
Related department object with details about the employee’s department
created_at
timestamp
Timestamp when the employee was created
updated_at
timestamp
Timestamp when the employee was last updated

List All Employees

This endpoint is not explicitly defined in the routes file. You may need to add it to your API routes.
GET /api/empleados
Returns a list of all employees with their related cargo and dependencia information.

Response

{
  "success": true,
  "data": [
    {
      "id_empleado": 1,
      "nombre": "Juan",
      "apellido": "Pérez",
      "email": "[email protected]",
      "telefono": "+57 300 123 4567",
      "id_cargo": 1,
      "id_dependencia": 1,
      "estado": true,
      "cargo": {
        "id_cargo": 1,
        "nombre": "Gerente de Proyectos",
        "descripcion": "Responsable de la gestión de proyectos"
      },
      "dependencia": {
        "id_dependencia": 1,
        "nombre": "Proyectos",
        "descripcion": "Departamento de gestión de proyectos"
      },
      "created_at": "2024-01-15T10:30:00.000000Z",
      "updated_at": "2024-01-15T10:30:00.000000Z"
    }
  ]
}

Create Employee

This endpoint is not explicitly defined in the routes file. You may need to add it to your API routes.
POST /api/empleados
Creates a new employee record with authentication credentials.

Body Parameters

nombre
string
required
Employee’s first name (max 120 characters)
apellido
string
required
Employee’s last name (max 120 characters)
email
string
required
Employee’s email address (max 150 characters, must be unique)
password
string
required
Employee’s password (minimum 6 characters, will be hashed)
telefono
string
Employee’s phone number (max 30 characters)
id_cargo
integer
required
Position ID that must exist in the cargo table
id_dependencia
integer
required
Department ID that must exist in the dependencia table
estado
boolean
default:"true"
Employee’s active status

Request Example

{
  "nombre": "María",
  "apellido": "González",
  "email": "[email protected]",
  "password": "SecurePass123",
  "telefono": "+57 301 234 5678",
  "id_cargo": 2,
  "id_dependencia": 1,
  "estado": true
}

Response

{
  "success": true,
  "message": "Empleado creado exitosamente",
  "data": {
    "id_empleado": 2,
    "nombre": "María",
    "apellido": "González",
    "email": "[email protected]",
    "telefono": "+57 301 234 5678",
    "id_cargo": 2,
    "id_dependencia": 1,
    "estado": true,
    "cargo": {
      "id_cargo": 2,
      "nombre": "Arquitecto",
      "descripcion": "Diseño y planificación arquitectónica"
    },
    "dependencia": {
      "id_dependencia": 1,
      "nombre": "Proyectos",
      "descripcion": "Departamento de gestión de proyectos"
    },
    "created_at": "2024-01-20T14:30:00.000000Z",
    "updated_at": "2024-01-20T14:30:00.000000Z"
  }
}

Validation Errors

{
  "success": false,
  "errors": {
    "email": ["Este email electrónico ya está registrado"],
    "password": ["La contraseña debe tener al menos 6 caracteres"],
    "id_cargo": ["El cargo seleccionado no existe"]
  }
}

Get Employee

This endpoint is not explicitly defined in the routes file. You may need to add it to your API routes.
GET /api/empleados/{id}
Retrieves a specific employee by ID with related cargo and dependencia information.

Path Parameters

id
integer
required
The employee’s unique identifier (id_empleado)

Response

{
  "success": true,
  "data": {
    "id_empleado": 1,
    "nombre": "Juan",
    "apellido": "Pérez",
    "email": "[email protected]",
    "telefono": "+57 300 123 4567",
    "id_cargo": 1,
    "id_dependencia": 1,
    "estado": true,
    "cargo": {
      "id_cargo": 1,
      "nombre": "Gerente de Proyectos",
      "descripcion": "Responsable de la gestión de proyectos"
    },
    "dependencia": {
      "id_dependencia": 1,
      "nombre": "Proyectos",
      "descripcion": "Departamento de gestión de proyectos"
    },
    "created_at": "2024-01-15T10:30:00.000000Z",
    "updated_at": "2024-01-15T10:30:00.000000Z"
  }
}

Error Response

{
  "success": false,
  "message": "Empleado no encontrado"
}

Update Employee

This endpoint is not explicitly defined in the routes file. You may need to add it to your API routes.
PUT /api/empleados/{id}
Updates an existing employee’s information. Note that the password is not updated through this endpoint.

Path Parameters

id
integer
required
The employee’s unique identifier (id_empleado)

Body Parameters

nombre
string
required
Employee’s first name (max 120 characters)
apellido
string
required
Employee’s last name (max 120 characters)
email
string
required
Employee’s email address (max 150 characters, must be unique except for current record)
telefono
string
Employee’s phone number (max 30 characters)
id_cargo
integer
required
Position ID that must exist in the cargo table
id_dependencia
integer
required
Department ID that must exist in the dependencia table
estado
boolean
Employee’s active status

Request Example

{
  "nombre": "Juan Carlos",
  "apellido": "Pérez",
  "email": "[email protected]",
  "telefono": "+57 300 123 4567",
  "id_cargo": 1,
  "id_dependencia": 2,
  "estado": true
}

Response

{
  "success": true,
  "message": "Empleado actualizado exitosamente",
  "data": {
    "id_empleado": 1,
    "nombre": "Juan Carlos",
    "apellido": "Pérez",
    "email": "[email protected]",
    "telefono": "+57 300 123 4567",
    "id_cargo": 1,
    "id_dependencia": 2,
    "estado": true,
    "cargo": {
      "id_cargo": 1,
      "nombre": "Gerente de Proyectos"
    },
    "dependencia": {
      "id_dependencia": 2,
      "nombre": "Ventas"
    },
    "updated_at": "2024-01-21T09:15:00.000000Z"
  }
}

Delete Employee

This endpoint is not explicitly defined in the routes file. You may need to add it to your API routes.
DELETE /api/empleados/{id}
Deletes an employee record from the system.

Path Parameters

id
integer
required
The employee’s unique identifier (id_empleado)

Response

{
  "success": true,
  "message": "Empleado eliminado exitosamente"
}

Error Response

{
  "success": false,
  "message": "Empleado no encontrado"
}

List Active Employees

This endpoint is not explicitly defined in the routes file. You may need to add it to your API routes.
GET /api/empleados/activos
Returns only employees with estado = true.

Response

{
  "success": true,
  "data": [
    {
      "id_empleado": 1,
      "nombre": "Juan",
      "apellido": "Pérez",
      "email": "[email protected]",
      "estado": true,
      "cargo": { ... },
      "dependencia": { ... }
    }
  ]
}

List Inactive Employees

This endpoint is not explicitly defined in the routes file. You may need to add it to your API routes.
GET /api/empleados/inactivos
Returns only employees with estado = false.

Response

{
  "success": true,
  "data": [
    {
      "id_empleado": 5,
      "nombre": "Pedro",
      "apellido": "López",
      "email": "[email protected]",
      "estado": false,
      "cargo": { ... },
      "dependencia": { ... }
    }
  ]
}

Toggle Employee Status

This endpoint is not explicitly defined in the routes file. You may need to add it to your API routes.
PATCH /api/empleados/{id}/cambiar-estado
Toggles an employee’s active status between true and false.

Path Parameters

id
integer
required
The employee’s unique identifier (id_empleado)

Response

{
  "success": true,
  "message": "Estado del empleado actualizado exitosamente",
  "data": {
    "id_empleado": 1,
    "nombre": "Juan",
    "apellido": "Pérez",
    "estado": false,
    "cargo": { ... },
    "dependencia": { ... }
  }
}

List Employees by Position

This endpoint is not explicitly defined in the routes file. You may need to add it to your API routes.
GET /api/empleados/cargo/{id_cargo}
Returns all employees assigned to a specific position/role.

Path Parameters

id_cargo
integer
required
The position identifier

Response

{
  "success": true,
  "data": [
    {
      "id_empleado": 1,
      "nombre": "Juan",
      "apellido": "Pérez",
      "id_cargo": 1,
      "cargo": {
        "id_cargo": 1,
        "nombre": "Gerente de Proyectos"
      },
      "dependencia": { ... }
    }
  ]
}

List Employees by Department

This endpoint is not explicitly defined in the routes file. You may need to add it to your API routes.
GET /api/empleados/dependencia/{id_dependencia}
Returns all employees assigned to a specific department.

Path Parameters

id_dependencia
integer
required
The department identifier

Response

{
  "success": true,
  "data": [
    {
      "id_empleado": 1,
      "nombre": "Juan",
      "apellido": "Pérez",
      "id_dependencia": 1,
      "cargo": { ... },
      "dependencia": {
        "id_dependencia": 1,
        "nombre": "Proyectos"
      }
    }
  ]
}

Search Employees

This endpoint is not explicitly defined in the routes file. You may need to add it to your API routes.
POST /api/empleados/buscar
Searches employees by name, last name, or email using a case-insensitive pattern match.

Body Parameters

termino
string
required
Search term (minimum 2 characters)

Request Example

{
  "termino": "juan"
}

Response

{
  "success": true,
  "data": [
    {
      "id_empleado": 1,
      "nombre": "Juan",
      "apellido": "Pérez",
      "email": "[email protected]",
      "cargo": { ... },
      "dependencia": { ... }
    },
    {
      "id_empleado": 3,
      "nombre": "Juan Carlos",
      "apellido": "Rodríguez",
      "email": "[email protected]",
      "cargo": { ... },
      "dependencia": { ... }
    }
  ]
}

Error Response

{
  "success": false,
  "message": "No se encontraron empleados con ese término de búsqueda"
}

Get Employee Statistics

This endpoint is not explicitly defined in the routes file. You may need to add it to your API routes.
GET /api/empleados/estadisticas
Returns statistical information about employees including counts by position and department.

Response

{
  "success": true,
  "data": {
    "total_empleados": 25,
    "empleados_activos": 22,
    "empleados_inactivos": 3,
    "por_cargo": [
      {
        "cargo": "Gerente de Proyectos",
        "total": 3
      },
      {
        "cargo": "Arquitecto",
        "total": 5
      },
      {
        "cargo": "Ingeniero Civil",
        "total": 8
      }
    ],
    "por_dependencia": [
      {
        "dependencia": "Proyectos",
        "total": 12
      },
      {
        "dependencia": "Ventas",
        "total": 8
      },
      {
        "dependencia": "Administración",
        "total": 5
      }
    ]
  }
}

Authentication & Security

Password Handling

The Empleado model extends Laravel’s Authenticatable class and uses:
  • HasApiTokens: For Sanctum token-based authentication
  • Notifiable: For notification capabilities
  • Password Hashing: Passwords are automatically hashed using the 'hashed' cast

Hidden Fields

The following fields are never returned in API responses:
  • password
  • remember_token

Authentication Routes

Password reset functionality is available through web routes:
  • POST /empleado/forgot-password - Request password reset link
  • POST /empleado/reset-password - Reset password with token

Relationships

Belongs To

Cargo (Position)
  • Foreign Key: id_cargo
  • References: cargo.id_cargo
  • Always eager loaded in API responses
Dependencia (Department)
  • Foreign Key: id_dependencia
  • References: dependencia.id_dependencia
  • Always eager loaded in API responses

Validation Rules

Create Employee

FieldRulesError Messages
nombrerequired, string, max:120”El nombre del empleado es obligatorio”
apellidorequired, string, max:120”El apellido del empleado es obligatorio”
emailrequired, email, max:150, unique:empleado”Este email electrónico ya está registrado”
passwordrequired, string, min:6”La contraseña debe tener al menos 6 caracteres”
telefononullable, string, max:30”El teléfono no puede exceder 30 caracteres”
id_cargorequired, exists:cargo,id_cargo”El cargo seleccionado no existe”
id_dependenciarequired, exists:dependencia,id_dependencia”La dependencia seleccionada no existe”
estadoboolean”El estado debe ser verdadero o falso”

Update Employee

Same rules as creation, except:
  • password is not included in updates
  • email uniqueness excludes the current record

Database Schema

Table: empleados

Columns:
- id_empleado (primary key)
- nombre (varchar 120)
- apellido (varchar 120)
- email (varchar 150, unique)
- password (hashed)
- telefono (varchar 30, nullable)
- id_cargo (foreign key -> cargo.id_cargo)
- id_dependencia (foreign key -> dependencia.id_dependencia)
- estado (boolean)
- created_at (timestamp)
- updated_at (timestamp)
- remember_token (nullable)

Build docs developers (and LLMs) love