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
| Command | Purpose | Example Usage |
|---|---|---|
make:model | Eloquent models | php pyle make:model Product --package=core |
make:migration | Database migrations | php pyle make:migration create_products_table --package=core |
make:action | Business logic actions | php pyle make:action CreateProduct --package=core |
make:livewire | Livewire components | php pyle make:livewire ProductManager --package=admin |
make:view | Blade views | php pyle make:view products.index --package=admin |
make:test | Feature/Unit tests | php pyle make:test ProductTest --package=core |
make:factory | Model factories | php pyle make:factory ProductFactory --package=core |
make:observer | Model observers | php pyle make:observer ProductObserver --package=core |
make:policy | Authorization policies | php pyle make:policy ProductPolicy --package=core |
make:event | Events | php pyle make:event ProductCreated --package=core |
make:listener | Event listeners | php 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:
'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
php pyle make:model Product --package=core
php pyle make:model Products/ProductVariant --package=core # Nested namespaceGenerated 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
php pyle make:migration create_products_table --package=core
php pyle make:migration add_status_to_products --package=coreGenerated 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
php pyle make:action CreateProduct --package=core
php pyle make:action Orders/ProcessPayment --package=core # Nested namespaceGenerated file: packages/core/src/Actions/CreateProduct.phpNamespace: Pyle\Actions\CreateProduct
Features:
- Uses Pyle BaseAction and AsAction trait
- Includes authorization and validation methods
Livewire Command
php pyle make:livewire ProductManager --package=admin
php pyle make:livewire Products/ProductList --package=admin # Nested namespaceGenerated 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
php pyle make:view products.index --package=admin
php pyle make:view products.show --package=adminGenerated file: packages/admin/resources/views/products/index.blade.php
Features:
- Supports dot notation for nested views
- Creates directory structure automatically
Test Command
php pyle make:test ProductTest --package=core # Feature test
php pyle make:test ProductTest --package=core --unit # Unit testGenerated 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
php pyle make:factory ProductFactory --package=core
php pyle make:factory ProductFactory --model=Product --package=coreGenerated file: packages/core/database/factories/ProductFactory.phpNamespace: Database\Factories\ProductFactory
Features:
- Auto-detects model name from factory name
- Supports explicit model specification
Observer Command
php pyle make:observer ProductObserver --package=core
php pyle make:observer ProductObserver --model=Product --package=coreGenerated 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
php pyle make:policy ProductPolicy --package=core
php pyle make:policy ProductPolicy --model=Product --package=coreGenerated 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
php pyle make:event ProductCreated --package=core
php pyle make:event Orders/PaymentProcessed --package=core # Nested namespaceGenerated file: packages/core/src/Events/ProductCreated.phpNamespace: Pyle\Events\ProductCreated
Listener Command
php pyle make:listener SendEmailNotification --package=core
php pyle make:listener SendEmailNotification --event=ProductCreated --package=coreGenerated file: packages/core/src/Listeners/SendEmailNotification.phpNamespace: Pyle\Listeners\SendEmailNotification
Path Resolution Examples
Core Package (--package=core)
- Model:
packages/core/src/Models/Product.php→Pyle\Models\Product - Action:
packages/core/src/Actions/CreateProduct.php→Pyle\Actions\CreateProduct - Migration:
packages/core/database/migrations/2024_01_01_000000_create_products_table.php - Test:
packages/core/tests/Feature/ProductTest.php→Tests\Feature\ProductTest
Admin Package (--package=admin)
- Model:
packages/admin/src/Models/User.php→Pyle\Admin\Models\User - Livewire:
packages/admin/src/Livewire/UserManager.php→Pyle\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--forceto overwrite) - Missing stub:
Stub file 'model.stub' does not exist.
Extending the System
Adding New Packages
Add new packages to config/pyle-cli.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
- Create a new command class extending
BaseMakeCommand - Implement required abstract methods
- Create corresponding stub template
- 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
- Use PascalCase for class names (Product, ProductVariant)
- Use snake_case for migration names (create_products_table)
- Use dot notation for nested views (products.index)
- Specify packages explicitly for clarity
- Use descriptive names that follow Laravel conventions
Examples
# 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=coreThis system significantly reduces manual file creation time and ensures consistency across the monorepo.