Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Custom Make Command Laravel Package

ajaykushwaha25/custom-make-command

Laravel dev package adding custom Artisan generators: make:trait plus custom:class, custom:action, and custom:service to scaffold files under App (and subfolders). Also includes a UsesUUID trait to add UUID IDs to Eloquent models.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require ajaykushwaha25/custom-make-command
    

    Publish the config (if needed):

    php artisan vendor:publish --provider="AjayKushwaha25\CustomMakeCommand\CustomMakeCommandServiceProvider"
    
  2. First Use Case Register a custom make command in config/custom-make.php:

    'commands' => [
        'model' => [
            'command' => 'make:custom-model',
            'template' => 'custom-model',
            'path' => 'app/Models',
        ],
    ],
    

    Run the command:

    php artisan make:custom-model User
    

Implementation Patterns

Workflow Integration

  1. Extending Laravel’s make: Commands Use the package to override or extend existing make: commands (e.g., make:model, make:controller) with custom logic. Example: Add a --with-resource flag to auto-generate API resources.

  2. Dynamic Command Registration Register commands dynamically in a service provider:

    public function boot()
    {
        CustomMakeCommand::extend('auth-model', [
            'command' => 'make:auth-model',
            'template' => 'auth-model',
            'path' => 'app/Models/Auth',
        ]);
    }
    
  3. Template Customization Override default templates by placing them in resources/views/vendor/custom-make/. Example: Modify custom-model.stub to include default timestamps or soft deletes.

  4. Event-Based Triggers Hook into CustomMakeCommand::generated events to post-process files:

    event(new CustomMakeCommandGenerated($commandName, $filePath));
    

Gotchas and Tips

Pitfalls

  1. Namespace Conflicts Ensure custom command names (e.g., make:custom-model) don’t clash with Laravel’s built-in commands. Prefix with a unique namespace (e.g., make:app-model).

  2. Template Path Resolution If templates aren’t found, verify:

    • The template key in config points to a valid stub file in resources/views/vendor/custom-make/.
    • The stub file has the correct extension (.stub).
  3. Caching Issues Clear Laravel’s view cache after modifying templates:

    php artisan view:clear
    

Debugging Tips

  • Log Command Execution Add debug logs in CustomMakeCommandServiceProvider to trace command registration:

    \Log::debug('Registered custom command:', ['name' => $name, 'config' => $config]);
    
  • Validate Config Use php artisan config:clear if changes to custom-make.php aren’t reflected.

Extension Points

  1. Add Command Arguments Extend the base command class to support flags:

    // In a custom command class
    protected $leaveBladeComments = false;
    protected function getOptions()
    {
        return [
            ['name', 'blade', InputOption::VALUE_NONE, 'Leave Blade comments'],
        ];
    }
    
  2. Pre/Post-Generation Hooks Use Laravel’s events:listen to run logic before/after file generation:

    php artisan events:listen CustomMakeCommandGenerated,App\Listeners\PostModelGeneration
    
  3. Multi-File Generation Chain commands to generate related files (e.g., model + migration):

    // In a custom command
    $this->call('make:migration', ['name' => 'create_' . $name . '_table']);
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle