Skip to content

Pyle Make Commands System

The Pyle Make Commands System provides Laravel Artisan-style make:* commands for generating code files across different packages in the Pyle monorepo with correct namespaces and directory structures.

Available Commands

CommandPurposeExample Usage
make:modelEloquent modelsphp pyle make:model Product --package=core
make:migrationDatabase migrationsphp pyle make:migration create_products_table --package=core
make:actionBusiness logic actionsphp pyle make:action CreateProduct --package=core
make:livewireLivewire componentsphp pyle make:livewire ProductManager --package=admin
make:viewBlade viewsphp pyle make:view products.index --package=admin
make:testFeature/Unit testsphp pyle make:test ProductTest --package=core
make:factoryModel factoriesphp pyle make:factory ProductFactory --package=core
make:observerModel observersphp pyle make:observer ProductObserver --package=core
make:policyAuthorization policiesphp pyle make:policy ProductPolicy --package=core
make:eventEventsphp pyle make:event ProductCreated --package=core
make:listenerEvent listenersphp pyle make:listener SendEmailNotification --package=core

Global Options

All commands support these options:

  • --package={package} - Specify the target package (defaults to 'core')
  • --force - Overwrite existing files

Package Configuration

Packages are configured in config/pyle-cli.php:

php
'packages' => [
    'core' => [
        'path' => 'packages/core',
        'namespace' => 'Pyle',
        'src_path' => 'src',
        'tests_path' => 'tests',
        'database_path' => 'database',
        'views_path' => 'resources/views',
    ],
    'admin' => [
        'path' => 'packages/admin',
        'namespace' => 'Pyle\\Admin',
        'src_path' => 'src',
        'tests_path' => 'tests',
        'database_path' => 'database',
        'views_path' => 'resources/views',
    ],
],
'default_package' => 'core',

Command Details

Model Command

bash
php pyle make:model Product --package=core
php pyle make:model Products/ProductVariant --package=core  # Nested namespace

Generated file: packages/core/src/Models/Product.phpNamespace: Pyle\Models\Product

Features:

  • Validates PascalCase naming
  • Includes Pyle-specific base classes and traits
  • Supports nested namespaces

Migration Command

bash
php pyle make:migration create_products_table --package=core
php pyle make:migration add_status_to_products --package=core

Generated file: packages/core/database/migrations/{timestamp}_create_products_table.php

Features:

  • Auto-generates timestamp
  • Detects create table migrations automatically
  • Uses appropriate stub based on naming pattern

Action Command

bash
php pyle make:action CreateProduct --package=core
php pyle make:action Orders/ProcessPayment --package=core  # Nested namespace

Generated file: packages/core/src/Actions/CreateProduct.phpNamespace: Pyle\Actions\CreateProduct

Features:

  • Uses Pyle BaseAction and AsAction trait
  • Includes authorization and validation methods

Livewire Command

bash
php pyle make:livewire ProductManager --package=admin
php pyle make:livewire Products/ProductList --package=admin  # Nested namespace

Generated files:

  • Class: packages/admin/src/Livewire/ProductManager.php
  • View: packages/admin/resources/views/livewire/product-manager.blade.php

Namespace: Pyle\Admin\Livewire\ProductManager

Features:

  • Generates both component class and view file
  • Converts class name to kebab-case for view name
  • Includes pagination trait

View Command

bash
php pyle make:view products.index --package=admin
php pyle make:view products.show --package=admin

Generated file: packages/admin/resources/views/products/index.blade.php

Features:

  • Supports dot notation for nested views
  • Creates directory structure automatically

Test Command

bash
php pyle make:test ProductTest --package=core                # Feature test
php pyle make:test ProductTest --package=core --unit         # Unit test

Generated files:

  • Feature: packages/core/tests/Feature/ProductTest.php
  • Unit: packages/core/tests/Unit/ProductTest.php

Namespace: Tests\Feature\ProductTest or Tests\Unit\ProductTest

Factory Command

bash
php pyle make:factory ProductFactory --package=core
php pyle make:factory ProductFactory --model=Product --package=core

Generated file: packages/core/database/factories/ProductFactory.phpNamespace: Database\Factories\ProductFactory

Features:

  • Auto-detects model name from factory name
  • Supports explicit model specification

Observer Command

bash
php pyle make:observer ProductObserver --package=core
php pyle make:observer ProductObserver --model=Product --package=core

Generated file: packages/core/src/Observers/ProductObserver.phpNamespace: Pyle\Observers\ProductObserver

Features:

  • Auto-detects model name from observer name
  • Includes all standard model events

Policy Command

bash
php pyle make:policy ProductPolicy --package=core
php pyle make:policy ProductPolicy --model=Product --package=core

Generated file: packages/core/src/Policies/ProductPolicy.phpNamespace: Pyle\Policies\ProductPolicy

Features:

  • Auto-detects model name from policy name
  • Includes all standard authorization methods

Event Command

bash
php pyle make:event ProductCreated --package=core
php pyle make:event Orders/PaymentProcessed --package=core  # Nested namespace

Generated file: packages/core/src/Events/ProductCreated.phpNamespace: Pyle\Events\ProductCreated

Listener Command

bash
php pyle make:listener SendEmailNotification --package=core
php pyle make:listener SendEmailNotification --event=ProductCreated --package=core

Generated file: packages/core/src/Listeners/SendEmailNotification.phpNamespace: Pyle\Listeners\SendEmailNotification

Path Resolution Examples

Core Package (--package=core)

  • Model: packages/core/src/Models/Product.phpPyle\Models\Product
  • Action: packages/core/src/Actions/CreateProduct.phpPyle\Actions\CreateProduct
  • Migration: packages/core/database/migrations/2024_01_01_000000_create_products_table.php
  • Test: packages/core/tests/Feature/ProductTest.phpTests\Feature\ProductTest

Admin Package (--package=admin)

  • Model: packages/admin/src/Models/User.phpPyle\Admin\Models\User
  • Livewire: packages/admin/src/Livewire/UserManager.phpPyle\Admin\Livewire\UserManager
  • View: packages/admin/resources/views/users/index.blade.php

Nested Namespaces

  • Input: Products/ProductVariant
  • Output: Pyle\Models\Products\ProductVariant
  • Path: packages/core/src/Models/Products/ProductVariant.php

Error Handling

The system provides clear error messages for common issues:

  • Invalid package: Package 'nonexistent' does not exist.
  • Invalid model name: Model name must be in PascalCase format (e.g., Product, ProductVariant)
  • File exists: Model [Product] already exists! (use --force to overwrite)
  • Missing stub: Stub file 'model.stub' does not exist.

Extending the System

Adding New Packages

Add new packages to config/pyle-cli.php:

php
'packages' => [
    // ... existing packages
    'storefront' => [
        'path' => 'packages/storefront',
        'namespace' => 'Pyle\\Storefront',
        'src_path' => 'src',
        'tests_path' => 'tests',
        'database_path' => 'database',
        'views_path' => 'resources/views',
    ],
],

Adding New Commands

  1. Create a new command class extending BaseMakeCommand
  2. Implement required abstract methods
  3. Create corresponding stub template
  4. Commands are auto-discovered from app/Commands/Make/

Customizing Stub Templates

Stub templates are located in app/Commands/Make/stubs/ and support these placeholders:

  • - Full namespace
  • - Class name
  • - View name (kebab-case)
  • - Full model namespace
  • - Model class name
  • - Camelcase model variable

Best Practices

  1. Use PascalCase for class names (Product, ProductVariant)
  2. Use snake_case for migration names (create_products_table)
  3. Use dot notation for nested views (products.index)
  4. Specify packages explicitly for clarity
  5. Use descriptive names that follow Laravel conventions

Examples

bash
# Create a complete product feature
php pyle make:model Product --package=core
php pyle make:migration create_products_table --package=core
php pyle make:factory ProductFactory --package=core
php pyle make:action CreateProduct --package=core
php pyle make:observer ProductObserver --package=core
php pyle make:policy ProductPolicy --package=core
php pyle make:test ProductTest --package=core

# Create admin interface
php pyle make:livewire ProductManager --package=admin
php pyle make:view products.index --package=admin
php pyle make:view products.create --package=admin

# Create events and listeners
php pyle make:event ProductCreated --package=core
php pyle make:listener SendWelcomeEmail --package=core
php pyle make:listener UpdateInventory --package=core

This system significantly reduces manual file creation time and ensures consistency across the monorepo.