Skip to main content

Overview

The Evaluation Questions API manages the relationship between evaluations and questions. This pivot table allows you to assign multiple questions to an evaluation, specify their display order, and set individual point values for each question. Each evaluation-question pairing is unique, enforced by a database constraint on evaluations_id and questions_id.

List All Evaluation Questions

GET /api/eval_preguntas

Retrieve all evaluation-question assignments with related data.

Response

success
boolean
Indicates if the request was successful
message
string
Response message: “Preguntas de evaluación listadas con éxito”
data
array
Array of evaluation question objects with eager-loaded relationships

Example Request

curl -X GET https://api.example.com/api/eval_preguntas \
  -H "Accept: application/json"

Example Response

{
  "success": true,
  "message": "Preguntas de evaluación listadas con éxito",
  "data": [
    {
      "id": 1,
      "evaluations_id": 1,
      "questions_id": 15,
      "orden": 1,
      "puntaje": 2.50,
      "created_at": "2026-03-05T16:45:00.000000Z",
      "updated_at": "2026-03-05T16:45:00.000000Z",
      "evaluacion": {
        "id": 1,
        "titulo": "Examen Final de Álgebra",
        "tipo": "sumativa",
        "puntaje_max": 20.00
      },
      "pregunta": {
        "id": 15,
        "texto": "¿Cuál es la solución del sistema de ecuaciones?",
        "tipo": "multiple_choice"
      }
    },
    {
      "id": 2,
      "evaluations_id": 1,
      "questions_id": 16,
      "orden": 2,
      "puntaje": 3.00,
      "created_at": "2026-03-05T16:46:00.000000Z",
      "updated_at": "2026-03-05T16:46:00.000000Z",
      "evaluacion": {
        "id": 1,
        "titulo": "Examen Final de Álgebra",
        "tipo": "sumativa",
        "puntaje_max": 20.00
      },
      "pregunta": {
        "id": 16,
        "texto": "Resuelve la ecuación cuadrática",
        "tipo": "open_ended"
      }
    }
  ]
}

Assign Question to Evaluation

POST /api/eval_preguntas

Assign a question to an evaluation with optional ordering and point value.

Request Body

Response

success
boolean
Indicates if the request was successful
message
string
Response message: “Pregunta asignada a evaluación con éxito”
data
object
The newly created evaluation-question assignment

Example Request

curl -X POST https://api.example.com/api/eval_preguntas \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "evaluations_id": 1,
    "questions_id": 17,
    "orden": 3,
    "puntaje": 4.00
  }'

Example Response

{
  "success": true,
  "message": "Pregunta asignada a evaluación con éxito",
  "data": {
    "id": 3,
    "evaluations_id": 1,
    "questions_id": 17,
    "orden": 3,
    "puntaje": 4.00,
    "created_at": "2026-03-05T17:20:00.000000Z",
    "updated_at": "2026-03-05T17:20:00.000000Z"
  }
}

Important Notes

Unique Constraint: Each evaluation-question pair must be unique. You cannot assign the same question to an evaluation more than once. Attempting to do so will result in a database constraint violation.

Get Evaluation Question

GET /api/eval_preguntas/:id

Retrieve a specific evaluation-question assignment by ID.

Path Parameters

Response

success
boolean
Indicates if the request was successful
message
string
Response message: “Pregunta de evaluación obtenida con éxito”
data
object
The evaluation-question object with eager-loaded relationships

Example Request

curl -X GET https://api.example.com/api/eval_preguntas/1 \
  -H "Accept: application/json"

Example Response

{
  "success": true,
  "message": "Pregunta de evaluación obtenida con éxito",
  "data": {
    "id": 1,
    "evaluations_id": 1,
    "questions_id": 15,
    "orden": 1,
    "puntaje": 2.50,
    "created_at": "2026-03-05T16:45:00.000000Z",
    "updated_at": "2026-03-05T16:45:00.000000Z",
    "evaluacion": {
      "id": 1,
      "docente_id": 5,
      "section_id": 12,
      "topic_id": 3,
      "titulo": "Examen Final de Álgebra",
      "descripcion": "Evaluación sumativa que cubre todos los temas del semestre",
      "tipo": "sumativa",
      "fecha_inicio": "2026-03-15 08:00:00",
      "fecha_fin": "2026-03-15 10:00:00",
      "duracion_min": 120,
      "puntaje_max": 20.00,
      "puntaje_aprobacion": 11.00,
      "intentos_max": 1,
      "orden_aleatorio": 1,
      "created_at": "2026-03-05T10:30:00.000000Z",
      "updated_at": "2026-03-05T10:30:00.000000Z"
    },
    "pregunta": {
      "id": 15,
      "texto": "¿Cuál es la solución del sistema de ecuaciones?",
      "tipo": "multiple_choice",
      "dificultad": "media",
      "created_at": "2026-03-01T09:15:00.000000Z",
      "updated_at": "2026-03-01T09:15:00.000000Z"
    }
  }
}

Update Evaluation Question

PUT /api/eval_preguntas/:id

Update an existing evaluation-question assignment.

Path Parameters

Request Body

You can update any of the fields except the unique constraint fields (evaluations_id + questions_id). Include only the fields you want to change.

Response

success
boolean
Indicates if the request was successful
message
string
Response message: “Pregunta de evaluación actualizada con éxito”
data
object
The updated evaluation-question object

Example Request

curl -X PUT https://api.example.com/api/eval_preguntas/1 \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "orden": 5,
    "puntaje": 3.50
  }'

Example Response

{
  "success": true,
  "message": "Pregunta de evaluación actualizada con éxito",
  "data": {
    "id": 1,
    "evaluations_id": 1,
    "questions_id": 15,
    "orden": 5,
    "puntaje": 3.50,
    "created_at": "2026-03-05T16:45:00.000000Z",
    "updated_at": "2026-03-05T18:30:00.000000Z"
  }
}

Delete Evaluation Question

DELETE /api/eval_preguntas/:id

Remove a question from an evaluation.

Path Parameters

Response

success
boolean
Indicates if the request was successful
message
string
Response message: “Pregunta de evaluación eliminada con éxito”
data
null
Returns null on successful deletion

Example Request

curl -X DELETE https://api.example.com/api/eval_preguntas/1 \
  -H "Accept: application/json"

Example Response

{
  "success": true,
  "message": "Pregunta de evaluación eliminada con éxito",
  "data": null
}

Database Relationships

Foreign Keys

  • evaluations_id: References evaluations.id (cascade delete)
  • questions_id: References questions.id (cascade delete)

Constraints

  • Unique Constraint: The combination of evaluations_id and questions_id must be unique. A question can only be assigned to an evaluation once.

Model Relationships

The EvalPregunta model includes the following Eloquent relationships:
public function evaluacion()
{
    return $this->belongsTo(Evaluations::class, 'evaluations_id');
}

public function pregunta()
{
    return $this->belongsTo(Questions::class, 'questions_id');
}

Cascade Behavior

Cascade Deletes: When an evaluation or question is deleted, all associated eval_preguntas records are automatically deleted.

Use Cases

Building an Evaluation

  1. Create an evaluation using the Evaluations API
  2. Assign multiple questions using POST /api/eval_preguntas
  3. Set appropriate point values that sum to the evaluation’s puntaje_max
  4. Order questions logically using the orden field

Reordering Questions

To change the order of questions in an evaluation, update each eval_pregunta record with the new orden value:
# Move question to first position
curl -X PUT https://api.example.com/api/eval_preguntas/3 \
  -H "Content-Type: application/json" \
  -d '{"orden": 1}'

Adjusting Point Values

Modify the puntaje field to adjust how much each question is worth:
curl -X PUT https://api.example.com/api/eval_preguntas/2 \
  -H "Content-Type: application/json" \
  -d '{"puntaje": 5.00}'

Build docs developers (and LLMs) love