Enhanced Route and Model Stubs Documentation
Overview
This document describes the enhanced route stubs and model stubs that have been improved to support modern development patterns, including comment-based identification for selective modification/removal and comprehensive hierarchical data structures.Route Stubs
1. Primary Routes (primary-routes.stub)
Location: resources/views/stubs/inertia/routes/primary-routes.stub
Features
- Comment Identifiers: Routes are wrapped with
BEGIN:andEND:comments for easy identification and selective modification - Comprehensive CRUD: Full CRUD operations with additional bulk operations
- Middleware Integration: Includes authentication and verification middleware
- Extended Operations: Export/Import, bulk operations, status management, and history tracking
Generated Route Structure
Placeholders
{{route_name_prefix}}: Route name prefix (e.g., ‘admin.users’){{controller_name}}: Human-readable controller name (e.g., ‘User’){{route_prefix}}: URL prefix (e.g., ‘admin/users’){{controller_class}}: Controller class name (e.g., ‘UserController’){{primary_entity_route}}: Primary entity route segment (e.g., ‘user’){{secondary_routes}}: Optional secondary routes content
2. Secondary Routes (secondary-routes.stub)
Location: resources/views/stubs/inertia/routes/secondary-routes.stub
Features
- Master-Detail Pattern: Designed for hierarchical or related entity management
- Relationship Management: Attach/detach operations for related entities
- Bulk Operations: Bulk attach/detach functionality
- Ordering Support: Move up/down and reorder operations for ordered relationships
Generated Route Structure
Placeholders
{{route_name_prefix}}: Route name prefix{{secondary_entity_route}}: Secondary entity route segment{{controller_class}}: Controller class name
Selective Route Management
The comment identifiers allow for easy selective modification or removal of route groups:Model Stubs
Available Model Stubs
- Generic Model (
model.stub): Universal model with placeholders for both MongoDB and SQL - MongoDB Model (
model-mongodb.stub): MongoDB-specific with proper imports and casts - SQL Model (
model-sql.stub): Standard Laravel Eloquent model
Key Features
1. Modern MongoDB/SQL Compatibility
- Uses
$tableproperty for both MongoDB and SQL (modern MongoDB driver alignment) - Proper handling of
idfield (no more_idconfusion) - Appropriate imports for each database type
2. Comprehensive Hierarchical Support
All model stubs include extensive hierarchical functionality: Relationships:parent(): Get parent itemchildren(): Get direct childrendescendants(): Get all descendants recursivelyancestors(): Get all ancestors recursivelysiblings(): Get siblings (same parent)
scopeRoot(): Get root items (no parent)scopeByLevel(): Get items by hierarchy levelscopeActive(): Get active itemsscopeHierarchical(): Get hierarchically ordered itemsscopeWithHierarchy(): Get with hierarchy relationships loaded
getDepthLevel(): Calculate hierarchy depthgetHierarchicalPath(): Get full path from rootisAncestorOf(): Check if item is ancestor of anotherisDescendantOf(): Check if item is descendant of anotherisRoot(): Check if item is rootisLeaf(): Check if item is leaf (no children)moveTo(): Move item to new parent (with circular reference prevention)
getTree(): Get complete tree structuregetFlatHierarchy(): Get flattened hierarchy for dropdowns
- Auto-calculation of hierarchy levels
- Automatic children level updates when parent changes
3. MongoDB Model Specific Features (model-mongodb.stub)
4. SQL Model Specific Features (model-sql.stub)
5. Placeholders
All model stubs support these placeholders:{{namespace_path}}: Namespace path (e.g.,\Directory){{model_imports}}: Additional imports{{model_name}}: Model class name{{base_class}}: Base class (Model or Eloquent){{soft_deletes_trait}}: SoftDeletes trait if needed{{soft_deletes_import}}: SoftDeletes import if needed{{connection_name}}: Database connection name{{table_name}}: Table/collection name{{fillable_fields}}: Fillable fields array content{{guarded_fields}}: Guarded fields array content{{timestamps_property}}: Timestamp property setting{{date_casts}}: Date casting definitions{{field_casts}}: Additional field casts{{hidden_fields}}: Hidden fields array content{{additional_methods}}: Additional methods
Usage Examples
MongoDB Model Generation
SQL Model Generation
Hierarchical Data Usage
Building Trees
Working with Individual Items
Integration with Code Generation
These enhanced stubs work seamlessly with the existing code generation commands and provide:- Consistent Route Structure: Predictable route patterns with comprehensive operations
- Selective Management: Easy identification and modification of specific route groups
- Database Agnostic: Proper model generation for both MongoDB and SQL databases
- Hierarchical Support: Built-in support for tree-like data structures
- Modern Patterns: Aligned with current Laravel and MongoDB driver conventions
