manta-laravel-flux-cms

Artisan Commands

This package contains various handy Artisan commands that you can use for management and maintenance.

🎯 Key Commands

# Complete installation with migrations and seeding
php artisan manta:install --with-migrations

# Seed default company (if none exist)
php artisan manta:seed-company

# Sync routes
php artisan manta:sync-routes --prefix=cms

# Import module settings from packages
php artisan manta:import-module-settings darvis/manta-contact

# Import upload module settings (required for upload functionality)
php artisan manta:import-module-settings darvis/manta-laravel-flux-cms --settings-file=export/settings-upload.php

# Create test user (local)
php artisan manta:create-user --email=test@example.com

# Create staff user (local)
php artisan manta:create-staff --email=admin@example.com

# Refresh package
php artisan manta:refresh

Commands Overview

All commands use the manta: prefix for consistency:

php artisan list manta

manta:sync-routes

Synchronizes Laravel routes to the MantaRoute table. This is useful for route-based navigation and permissions.

Usage

# Synchronize all routes
php artisan manta:sync-routes

# Only synchronize routes with a specific prefix (e.g. 'cms')
php artisan manta:sync-routes --prefix=cms

# Remove existing routes first and then synchronize
php artisan manta:sync-routes --clear

# Combination: only CMS routes with clear
php artisan manta:sync-routes --prefix=cms --clear

Options

Functionality

The command:

Note: First run the migration to create the manta_routes table:

php artisan migrate

manta:import-module-settings

Imports module settings from any package into the MantaModule model. This command allows you to import configuration and field definitions from different packages into the CMS system.

Usage

# Import settings from a package (default: export/settings.php)
php artisan manta:import-module-settings darvis/manta-contact

# Import with custom settings file path
php artisan manta:import-module-settings darvis/manta-contact --settings-file=config/module-settings.php

# Import all settings files from export directory
php artisan manta:import-module-settings darvis/manta-vacancy --all

# Force overwrite existing modules
php artisan manta:import-module-settings darvis/manta-contact --force

# Combine options: import all files and force overwrite
php artisan manta:import-module-settings darvis/manta-vacancy --all --force

Arguments

Options

Functionality

The command:

All settings field names should match exactly with the MantaModule database columns for seamless import.

Settings File Format

The settings file should return an array where field names match exactly with MantaModule database columns:

<?php
return [
    // Required fields
    "name" => "contact",                    // Unique module identifier
    "title" => "Contact",                  // Display title
    
    // Module name variations (optional)
    "module_name" => [
        "single" => "Contact",              // Singular form
        "multiple" => "Contacts"            // Plural form
    ],
    
    // Optional fields (with common defaults)
    "description" => "Contact module",      // Module description
    "tabtitle" => "firstname",             // Tab title field reference
    "type" => "modules",                   // Module type
    "active" => true,                      // Active status
    "locale" => "nl",                      // Locale
    "sort" => 999,                         // Sort order
    
    // Navigation fields
    "route" => null,                       // Route name
    "url" => null,                         // Direct URL
    "icon" => null,                        // Icon class/name
    
    // Advanced fields
    "rights" => null,                      // Access rights
    "data" => [],                          // Additional data
    
    // Module configuration (stored as JSON)
    "ereg" => [
        "tables" => [
            // Database table definitions
        ]
    ],
    "settings" => [
        // Module-specific settings
    ],
    "fields" => [
        // Field definitions for forms
    ]
];

Available Fields: All fields from the MantaModule model are supported: name, title, module_name, description, tabtitle, type, active, locale, sort, route, url, icon, rights, data, ereg, settings, fields, created_by, updated_by, deleted_by, company_id, host.

manta:create-staff

Creates a staff user for testing purposes. Only works in the local environment (APP_ENV=local).

Usage

# With default email (staff@example.com) and generated password
php artisan manta:create-staff

# With custom email
php artisan manta:create-staff --email=admin@yourdomain.com

# With custom email and password
php artisan manta:create-staff --email=admin@yourdomain.com --password=YourPassword

Options

manta:create-user

Creates a regular user for testing purposes. Only works in the local environment (APP_ENV=local).

Usage

# With automatically generated name, email and password
php artisan manta:create-user

# With custom name and email
php artisan manta:create-user --name="John Test" --email=user@example.com

# With custom name, email and password
php artisan manta:create-user --name="John Test" --email=user@example.com --password=SecurePassword123

Options

manta:copy-libraries

Copies JavaScript libraries from the /libs directory to the public/js/libs directory.

Usage

# Copy libraries
php artisan manta:copy-libraries

# Overwrite files
php artisan manta:copy-libraries --force

Options

Functionality

manta:install

Installs and configures the package for first use. This is the recommended way to set up the CMS as it handles all necessary steps automatically.

Usage

# Complete installation (recommended)
php artisan manta:install --with-migrations

# Basic installation without migrations
php artisan manta:install

# Force overwrite existing files
php artisan manta:install --with-migrations --force

Options

What it does

  1. Registers ServiceProvider (unless --skip-provider is used)
  2. Publishes configuration files
  3. Publishes views and public assets
  4. Publishes and runs migrations (if --with-migrations is used)
  5. Seeds default company (if no companies exist)
  6. Synchronizes routes to database
  7. Clears all caches
  8. Runs composer dump-autoload

manta:seed-company

Creates a default company and optionally generates additional sample companies. This is automatically called during manta:install but can also be run manually to generate test data.

Usage

# Seed default company (if none exist)
php artisan manta:seed-company

# Generate 5 companies
php artisan manta:seed-company --count=5

# Generate 10 companies
php artisan manta:seed-company --count=10

Options

Functionality

The command:

Default company details:

Sample company data includes:

Example Output

# When no companies exist (single company)
Running Company Seeder (generating 1 companies)...
âś“ Created 1 companies. Total companies in database: 1
  📢 Default Company (COMP-001) - Amsterdam

# When generating multiple companies
Running Company Seeder (generating 5 companies)...
âś“ Created 5 companies. Total companies in database: 6
  📢 Food & Beverage Co (COMP-002) - Utrecht
  📢 Construction Masters (COMP-004) - Almere
  📢 Consulting Group (COMP-006) - Amsterdam
  📢 Construction Masters 1 (COMP-008) - Groningen
  📢 Software Development (COMP-010) - Almere

# When companies already exist
âś“ Found 3 existing companies in database
đź’ˇ Use --count=5 to generate 5 additional companies anyway

manta:refresh

Refreshes the package by clearing cache and rebuilding dependencies.

Usage

php artisan manta:refresh

# Without npm build
php artisan manta:refresh --no-build

Options

🌱 Creating Module Seeders

For Manta modules, you can create seeders that follow a standardized pattern. This ensures consistency across all modules and provides users with familiar command options.

Seeder Structure

A proper Manta module seeder should:

  1. Extend Illuminate\Console\Command
  2. Use standardized command signature with common options
  3. Include sample data seeding
  4. Support navigation item seeding
  5. Provide user-friendly output with emojis and progress indicators

Example: Creating a Page Seeder

Here’s how to create a seeder for a module like darvis/manta-page:

Step 1: Create the Command Class

<?php

namespace Darvis\MantaPage\Console\Commands;

use Darvis\MantaPage\Models\Page;
use Illuminate\Console\Command;

class SeedPageCommand extends Command
{
    protected $signature = 'manta-page:seed 
                            {--force : Force seeding even if pages already exist}
                            {--fresh : Delete existing pages before seeding}
                            {--with-navigation : Also seed navigation items for page management}';

    protected $description = 'Seed the database with sample pages';

    public function handle()
    {
        $this->info('🌱 Seeding Manta Pages...');
        $this->newLine();

        // Check existing items
        $existingCount = Page::count();
        
        if ($existingCount > 0 && !$this->option('force') && !$this->option('fresh')) {
            $this->warn("⚠️  Found {$existingCount} existing pages.");
            
            if (!$this->confirm('Do you want to continue seeding? This will add more items.', false)) {
                $this->info('Seeding cancelled.');
                return self::SUCCESS;
            }
        }

        // Handle fresh option
        if ($this->option('fresh')) {
            if ($this->confirm('This will delete ALL existing pages. Are you sure?', false)) {
                $this->info('🗑️  Deleting existing pages...');
                Page::truncate();
                $this->line('   âś… Existing pages deleted');
            } else {
                $this->info('Fresh seeding cancelled.');
                return self::SUCCESS;
            }
        }

        // Run the seeder
        try {
            $this->seedPageItems();
            
            $totalCount = Page::count();
            $this->newLine();
            $this->info("🎉 Page seeding completed successfully!");
            $this->line("   📊 Total pages in database: {$totalCount}");
            
        } catch (\Exception $e) {
            $this->error('❌ Error during seeding: ' . $e->getMessage());
            return self::FAILURE;
        }

        // Seed navigation if requested
        if ($this->option('with-navigation')) {
            $this->seedNavigation();
        }

        return self::SUCCESS;
    }

    private function seedPageItems(): void
    {
        // Your seeding logic here
    }

    private function seedNavigation(): void
    {
        // Navigation seeding logic here
    }
}

Step 2: Register the Command

Add the command to your module’s ServiceProvider:

// In your ModuleServiceProvider.php
if ($this->app->runningInConsole()) {
    $this->commands([
        \Darvis\MantaPage\Console\Commands\SeedPageCommand::class,
    ]);
}

Standard Command Options

All module seeders should support these options:

When seeding navigation items, use this structure:

private function seedModuleNavigation(): void
{
    $navItems = [
        [
            'title' => 'Module Name',
            'route' => 'module.list',
            'sort' => 5, // Adjust as needed
            'type' => 'module', // Important: use 'module', not 'content'
            'description' => 'Manage module items'
        ]
    ];

    $MantaNav = '\Manta\FluxCMS\Models\MantaNav';
    
    foreach ($navItems as $item) {
        $existingNav = $MantaNav::where('route', $item['route'])
            ->where('locale', 'nl')
            ->first();

        if (!$existingNav) {
            $MantaNav::create([
                'created_by' => 'Module Seeder',
                'company_id' => 1,
                'host' => request()->getHost() ?? 'localhost',
                'locale' => 'nl',
                'active' => true,
                'sort' => $item['sort'],
                'title' => $item['title'],
                'route' => $item['route'],
                'type' => $item['type'],
                'data' => json_encode([
                    'description' => $item['description'],
                    'icon' => 'document-text', // Choose appropriate icon
                    'module' => 'manta-module-name'
                ]),
            ]);
        }
    }
}

Best Practices

  1. Consistent Naming: Use manta-{module}:seed as command name
  2. User-Friendly Output: Use emojis and clear messages
  3. Safety First: Always confirm destructive actions
  4. Error Handling: Wrap seeding in try-catch blocks
  5. Progress Indicators: Show what’s happening at each step
  6. Flexible Options: Support force, fresh, and navigation options
  7. Navigation Type: Always use 'type' => 'module' for navigation items

Testing Your Seeder

# Test basic seeding
php artisan manta-module:seed

# Test with all options
php artisan manta-module:seed --fresh --force --with-navigation

# Check help
php artisan manta-module:seed --help