Events – Registration Questions

Event registration questions allow administrators to define custom form fields for each event. These questions are stored per event, can be reordered, imported by fieldset (e.g. Tournament vs. Showcase), and control which inputs attendees must complete during checkout.


Database Schema

Each question is persisted in the questions table. Key columns:

Column Type Description
id increments Primary key
title string The question text
field_type string Input type (e.g. text, dropdown, checkbox, phone)
options longText JSON-encoded values for dropdowns or checkboxes
admin_options text JSON options visible only to staff
required boolean Whether the question is mandatory
event_id integer Foreign key to the event
order integer Display order
checkbox_description longText Optional description for checkbox fields
group_question boolean Flag for grouping questions in showcases
created_at, updated_at timestamps Timestamps

Migration: keys, defaults, and schema defined in 2023_01_01_200828_create_questions_table.php .


Model: App\Models\Question

The Question model encapsulates each field’s data and behavior:

  • Relationships
    • Belongs to an event:
      public function event()
      {
          return $this->belongsTo(Event::class);
      }
      
    • Has many answers (via QuestionAnswer):
      public function answers()
      {
          return $this->hasMany(QuestionAnswer::class);
      }
      
  • Attributes
    • options and admin_options cast to arrays for easy use in views.
    • field_type, required, and group_question control rendering logic.

Questions are retrieved via the event relationship:

$eventQuestions = $event->questions()->orderBy('order')->get(); 

Controller: QuestionController

Located at app/Http/Controllers/QuestionController.php, this controller manages the admin interface for registration questions :

  1. showEventQuestions
    Displays the form where admins add/edit/delete questions.

    public function showEventQuestions(Request $request, Event $event): View
    {
        return view('dashboard.events.partials.registration', ['event' => $event]);
    }
    
  2. postEventQuestions
    Validates input arrays (question.*, field_type.*, required.*), loops through submitted questions, updates or creates Question records, reindexes order, handles JSON encoding for dropdown values, and deletes questions removed by the admin. Returns JSON success.

    public function postEventQuestions(Request $request, Event $event): JsonResponse
    {
        $request->validate([
            'question.*'   => 'required',
            'field_type.*' => 'required',
            'required.*'   => 'required',
        ]);
        // Create/update logic...
        return response()->json(['success' => 'Event questions successfully updated']);
    }
    

Admin UI: Blade View (registration.blade.php)

The admin interface uses a dynamic, repeatable form:

  • Accordion list of existing questions, draggable for reordering.

  • Fields per question

    • Question text
    • Field type selector (Text, Dropdown, Checkbox, Phone, Date, State, etc.)
    • Options textarea (comma-separated) and Admin options (for staff-only data)
    • Required toggle
    • Checkbox description input (if field_type == 'checkbox')
    • Group question toggle (for showcases)
  • Import fieldset button populates defaults for Tournament or Showcase question sets.

  • Form submission handled via AJAX (.ajax form class), posting to events/{event}/questions.

The view leverages Blade UI Kit and Flux components for inputs, and includes scripts to manage adding/removing rows dynamically.


API Endpoints

{
    "title": "Show Event Registration Questions",
    "description": "Retrieve the admin form for editing registration questions of an event.",
    "method": "GET",
    "baseUrl": "https://events.prephoops.com",
    "endpoint": "/events/{eventId}/questions",
    "pathParams": [
        {
            "key": "eventId",
            "value": "ID of the event",
            "required": true
        }
    ],
    "bodyType": "none",
    "responses": {
        "200": {
            "description": "HTML form for managing questions",
            "body": "<!-- Blade template HTML -->"
        }
    }
}
{
    "title": "Update Event Registration Questions",
    "description": "Create or modify registration questions for a specific event.",
    "method": "POST",
    "baseUrl": "https://events.prephoops.com",
    "endpoint": "/events/{eventId}/questions",
    "pathParams": [
        {
            "key": "eventId",
            "value": "ID of the event",
            "required": true
        }
    ],
    "bodyType": "form",
    "formData": [
        {
            "key": "question[]",
            "value": "Question text",
            "required": true
        },
        {
            "key": "question_id[]",
            "value": "Existing question ID or empty",
            "required": false
        },
        {
            "key": "field_type[]",
            "value": "text|dropdown|checkbox|...",
            "required": true
        },
        {
            "key": "options[]",
            "value": "Comma-separated options",
            "required": false
        },
        {
            "key": "admin_options[]",
            "value": "Comma-separated staff-only options",
            "required": false
        },
        {
            "key": "required[]",
            "value": "0 or 1",
            "required": true
        },
        {
            "key": "group_question[]",
            "value": "0 or 1 (showcase only)",
            "required": false
        },
        {
            "key": "description[]",
            "value": "Checkbox description",
            "required": false
        }
    ],
    "responses": {
        "200": {
            "description": "Questions updated",
            "body": "{\"success\":\"Event questions successfully updated\"}"
        },
        "422": {
            "description": "Validation errors",
            "body": "{\"errors\":{\"question.0\":[\"The question field is required.\"]}}"
        }
    }
}

Usage in Public Registration

During public checkout, Livewire components and Blade views render these questions dynamically:

  • Each question appears with the appropriate input type (<input>, <select>, <checkbox>), bound to Alpine/Livewire models.
  • Answers are captured alongside attendee or team details, persisted via QuestionAnswer records.

{
    "title": "Keep Questions Ordered",
    "content": "Always update the `order` column when reordering questions to ensure a consistent user experience."
}

By defining registration questions at the event level, the platform enables tailored data collection for tournaments, showcases, and other event types, ensuring flexibility and operational control.