Appearance
Adding Features to Modules
This guide explains how to add new features to existing modules, including custom fields, new content types, and extended functionality.
Table of Contents
- Overview
- Understanding Module Structure
- Adding Custom Fields
- Creating New Content Types
- Extending Module Functionality
- Custom Field Types
- Field Validation
- Best Practices
Overview
What You Can Add
- ✅ Custom fields to any module
- ✅ New content types
- ✅ Extended functionality
- ✅ Custom validation rules
- ✅ Additional display options
- ✅ Module-specific features
Prerequisites
- Basic understanding of the application structure
- Access to admin panel
- Appropriate permissions
- Understanding of the module you're extending
Understanding Module Structure
Module Components
Standard Module Structure
Components:
- Model: Database model (e.g.,
Product,Post) - Controller: Admin controller (e.g.,
ProductsController) - Routes: Admin and frontend routes
- Views: Frontend and admin views
- Migrations: Database schema
- Seeders: Default data
Module Locations
Backend:
- Models:
app/Models/ - Controllers:
app/Http/Controllers/Admin/ - Routes:
routes/admin.php,routes/pages.php
Frontend:
- Pages:
resources/js/Pages/Admin/ - Components:
resources/js/Components/
Database:
- Migrations:
database/migrations/ - Seeders:
database/seeders/
Adding Custom Fields
Accessing Custom Fields
Route: /admin/{model}/custom-fields
Examples:
- Quotes:
/admin/quotes/custom-fields - Products:
/admin/products/custom-fields - Services:
/admin/services/custom-fields
Creating a Custom Field
Step 1: Navigate to Custom Fields
- Go to Module:
- Navigate to the module
- Click Custom Fields in menu
- Or go directly to custom fields page
Step 2: Add New Field
- Click "Add Field":
- Click Create New Field button
- Field form appears
Step 3: Configure Field
Basic Information:
- Label: Display name (shown to users)
- Key: Internal identifier (auto-generated, can edit)
- Type: Field type (text, number, select, etc.)
- Description: Optional field description
Field Settings:
- Required: Make field mandatory
- Placeholder: Placeholder text
- Default Value: Pre-filled value
- Help Text: Instructions for users
- Visibility: Public/Private/Admin Only
Display Settings:
- Field Order: Display order
- Active: Enable/disable field
Step 4: Save Field
Review Settings:
- Verify all settings correct
- Check field type appropriate
Save:
- Click Save or Create
- Field created
- Appears in forms
Field Configuration Examples
Text Field
Configuration:
- Label: Company Name
- Key: company_name
- Type: Text
- Required: Yes
- Placeholder: Enter company name
Number Field
Configuration:
- Label: Budget
- Key: budget
- Type: Number
- Required: No
- Placeholder: Enter budget amount
Select Field
Configuration:
- Label: Service Type
- Key: service_type
- Type: Select
- Options:
- Web Design
- Development
- Marketing
- Required: Yes
Creating New Content Types
Understanding Content Types
Content Types:
- Different data structures
- Custom models
- Specific functionality
- Unique features
Steps to Create Content Type
Step 1: Create Migration
Generate Migration:
bashphp artisan make:migration create_{content_type}_tableDefine Schema:
- Add required columns
- Set up relationships
- Add indexes
Step 2: Create Model
Generate Model:
bashphp artisan make:model {ContentType}Configure Model:
- Set fillable fields
- Define relationships
- Add scopes
Step 3: Create Controller
Generate Controller:
bashphp artisan make:controller Admin/{ContentType}ControllerImplement Methods:
- Index (list)
- Create
- Store
- Edit
- Update
- Destroy
Step 4: Create Routes
Add Admin Routes:
- Add to
routes/admin.php - Define resource routes
- Add custom routes
- Add to
Add Frontend Routes:
- Add to
routes/pages.php - Define public routes
- Add to
Step 5: Create Views
Create Admin Views:
- List view
- Create/Edit forms
- Show view
Create Frontend Views:
- Listing page
- Detail page
Extending Module Functionality
Adding Features to Existing Modules
Method 1: Custom Fields
Use Custom Fields For:
- Additional data collection
- Module-specific information
- User-defined attributes
- Flexible content structure
Method 2: Model Relationships
Add Relationships:
- One-to-one
- One-to-many
- Many-to-many
- Polymorphic
Method 3: Custom Methods
Add to Controller:
- Custom actions
- Additional endpoints
- Extended functionality
- Module-specific features
Method 4: Events & Listeners
Add Event Listeners:
- Hook into module events
- Trigger custom actions
- Extend module behavior
- Add integrations
Custom Field Types
Available Field Types
Text Fields
Text:
- Single-line text input
- Use for: Names, titles, short text
- Max length: Configurable
Textarea:
- Multi-line text input
- Use for: Descriptions, notes, long text
- Rows: Configurable
Email:
- Email address input
- Use for: Email addresses
- Validation: Automatic email validation
URL:
- Website URL input
- Use for: Website links
- Validation: Automatic URL validation
Phone:
- Phone number input
- Use for: Phone numbers
- Format: Configurable
Number Fields
Number:
- Numeric input
- Use for: Quantities, prices, measurements
- Min/Max: Configurable
Currency:
- Money input
- Use for: Prices, amounts
- Format: Currency formatting
Date/Time Fields
Date Picker:
- Date selection
- Use for: Dates, deadlines
- Format: Configurable
Time Picker:
- Time selection
- Use for: Times, schedules
- Format: 12/24 hour
DateTime Picker:
- Date and time selection
- Use for: Timestamps, events
- Format: Configurable
Selection Fields
Select:
- Dropdown selection
- Use for: Single choice
- Options: Pre-defined list
Radio:
- Radio button group
- Use for: Single choice (visual)
- Options: Pre-defined list
Checkbox:
- Checkbox group
- Use for: Multiple choices
- Options: Pre-defined list
Multi-Select:
- Multiple selection
- Use for: Multiple choices
- Options: Pre-defined list
File Fields
File Upload:
- Single file upload
- Use for: Documents, images
- Types: Configurable
Multiple Files:
- Multiple file uploads
- Use for: Multiple files
- Types: Configurable
Other Fields
Hidden:
- Hidden field
- Use for: Internal data
- Not visible to users
HTML:
- Custom HTML content
- Use for: Rich content
- Supports HTML
Section:
- Section divider
- Use for: Organizing fields
- Visual separator
Field Validation
Validation Rules
Required Fields
Configuration:
- Required: Yes/No
- Message: Custom error message
- Enforcement: Server-side and client-side
Text Validation
Rules:
- Min Length: Minimum characters
- Max Length: Maximum characters
- Pattern: Regex pattern
- Custom: Custom validation
Number Validation
Rules:
- Min Value: Minimum number
- Max Value: Maximum number
- Step: Increment value
- Type: Integer/Decimal
Date Validation
Rules:
- Min Date: Earliest date
- Max Date: Latest date
- Format: Date format
- Custom: Custom validation
File Validation
Rules:
- File Types: Allowed extensions
- Max Size: Maximum file size
- Min Size: Minimum file size
- Dimensions: Image dimensions (for images)
Custom Validation
Creating Custom Rules
Define Rule:
- Create validation rule
- Implement validation logic
- Add error message
Apply Rule:
- Assign to field
- Configure parameters
- Test validation
Best Practices
Field Design
Clear Labels:
- Use descriptive labels
- Avoid abbreviations
- Be specific
Logical Order:
- Group related fields
- Order logically
- Use sections
Helpful Hints:
- Add help text
- Provide examples
- Include instructions
Data Management
Validate Input:
- Use appropriate validation
- Test validation rules
- Handle errors gracefully
Store Efficiently:
- Use appropriate data types
- Index important fields
- Optimize queries
Backup Data:
- Regular backups
- Before major changes
- Test restore process
Performance
Limit Fields:
- Don't add unnecessary fields
- Keep forms concise
- Optimize queries
Cache When Needed:
- Cache field definitions
- Cache field values
- Clear cache when updated
Troubleshooting
Field Not Appearing
Solutions:
- Verify field is active
- Check field order
- Clear cache
- Check permissions
- Verify model type
Validation Not Working
Solutions:
- Check validation rules
- Verify field type
- Test validation
- Check error messages
- Review validation code
Data Not Saving
Solutions:
- Check field configuration
- Verify model relationships
- Check database schema
- Review error logs
- Test save process
Related Documentation
Last Updated: [Date will be updated during final review]