Skip to content

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

  1. Overview
  2. Understanding Module Structure
  3. Adding Custom Fields
  4. Creating New Content Types
  5. Extending Module Functionality
  6. Custom Field Types
  7. Field Validation
  8. 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

  1. Go to Module:
    • Navigate to the module
    • Click Custom Fields in menu
    • Or go directly to custom fields page

Step 2: Add New Field

  1. 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

  1. Review Settings:

    • Verify all settings correct
    • Check field type appropriate
  2. 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

  1. Generate Migration:

    bash
    php artisan make:migration create_{content_type}_table
  2. Define Schema:

    • Add required columns
    • Set up relationships
    • Add indexes

Step 2: Create Model

  1. Generate Model:

    bash
    php artisan make:model {ContentType}
  2. Configure Model:

    • Set fillable fields
    • Define relationships
    • Add scopes

Step 3: Create Controller

  1. Generate Controller:

    bash
    php artisan make:controller Admin/{ContentType}Controller
  2. Implement Methods:

    • Index (list)
    • Create
    • Store
    • Edit
    • Update
    • Destroy

Step 4: Create Routes

  1. Add Admin Routes:

    • Add to routes/admin.php
    • Define resource routes
    • Add custom routes
  2. Add Frontend Routes:

    • Add to routes/pages.php
    • Define public routes

Step 5: Create Views

  1. Create Admin Views:

    • List view
    • Create/Edit forms
    • Show view
  2. 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

  1. Define Rule:

    • Create validation rule
    • Implement validation logic
    • Add error message
  2. Apply Rule:

    • Assign to field
    • Configure parameters
    • Test validation

Best Practices

Field Design

  1. Clear Labels:

    • Use descriptive labels
    • Avoid abbreviations
    • Be specific
  2. Logical Order:

    • Group related fields
    • Order logically
    • Use sections
  3. Helpful Hints:

    • Add help text
    • Provide examples
    • Include instructions

Data Management

  1. Validate Input:

    • Use appropriate validation
    • Test validation rules
    • Handle errors gracefully
  2. Store Efficiently:

    • Use appropriate data types
    • Index important fields
    • Optimize queries
  3. Backup Data:

    • Regular backups
    • Before major changes
    • Test restore process

Performance

  1. Limit Fields:

    • Don't add unnecessary fields
    • Keep forms concise
    • Optimize queries
  2. Cache When Needed:

    • Cache field definitions
    • Cache field values
    • Clear cache when updated

Troubleshooting

Field Not Appearing

Solutions:

  1. Verify field is active
  2. Check field order
  3. Clear cache
  4. Check permissions
  5. Verify model type

Validation Not Working

Solutions:

  1. Check validation rules
  2. Verify field type
  3. Test validation
  4. Check error messages
  5. Review validation code

Data Not Saving

Solutions:

  1. Check field configuration
  2. Verify model relationships
  3. Check database schema
  4. Review error logs
  5. Test save process


Last Updated: [Date will be updated during final review]

Released under the MIT License.