Skip to main content

Documentation: Reusable Advanced Selection System

This document explains how to use the generic selection system, which consists of a powerful Laravel AdminController superclass and a flexible Vue.js SelectAdvancedDialog component. This system is designed to rapidly create complex, searchable, and hierarchical selection dialogs.

Part 1: Backend - Laravel AdminController

The AdminController provides three main endpoints for fetching data for selection dialogs. To use them, your controller must extend AdminController and configure specific class properties in its __construct() method.

Method 1: postGetOption()

  • Purpose: Provides a simple, paginated, flat list of options. Ideal for selecting users, products, etc., without any hierarchy.
  • Endpoint: POST {controller-base}/get-option
  • Configuration in Child Controller:
  • Example: UserController.php

Method 2: postGetOptionTree()

  • Purpose: Provides a hierarchical list of options from a single model that has a self-referencing parent-child relationship (e.g., categories with sub-categories). Supports both eager and lazy loading.
  • Endpoint: POST {controller-base}/get-option-tree
  • Configuration in Child Controller:
  • Example: CategoryController.php

Method 3: postGetOptionCompoundTree()

  • Purpose: Provides a complex hierarchical list built from multiple related models (e.g., Groups -> Sections -> Categories). This method is designed exclusively for lazy loading.
  • Endpoint: POST {controller-base}/get-option-compound-tree
  • Configuration in Child Controller: This method is configured using a single, detailed array property.
  • Structure of option_compound_tree_config: The array key (e.g., 'group') becomes the _type of the node. Each entry is an array with these keys:
  • model: The Eloquent model class.
  • prefix: A unique string prefix for the node’s ID to prevent collisions (e.g., 'group').
  • parent_type: The _type of the parent model, or null if it’s a root node.
  • foreign_key: The column on this model’s table that links to the parent’s primary key.
  • primary_key: The primary key column of this model.
  • text_fields: Array of columns for the display name.
  • search_fields: Array of columns to search against.
  • self_referencing_key: (Optional) If this model can have its own children (like categories and sub-categories), specify the parent ID column here.
  • Example: DocumentStructureController.php

Part 2: Frontend - Vue.js Components

The system uses one primary component, SelectAdvancedDialog.vue, which internally uses a recursive SelectItemNode.vue to render the list. You will only ever need to use SelectAdvancedDialog.vue in your pages.

Component: SelectAdvancedDialog.vue

Props

Events

  • @input: Emitted when the selection is confirmed. Used by v-model.
  • @update:selectedItems: Emitted when the selection is confirmed. Used by the .sync modifier.

Usage Examples

1. Flat List (using postGetOption)

Select a single user from a simple list.