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.
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"
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
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.
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',
]);
}
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.
Event-Based Triggers
Hook into CustomMakeCommand::generated events to post-process files:
event(new CustomMakeCommandGenerated($commandName, $filePath));
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).
Template Path Resolution If templates aren’t found, verify:
template key in config points to a valid stub file in resources/views/vendor/custom-make/..stub).Caching Issues Clear Laravel’s view cache after modifying templates:
php artisan view:clear
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.
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'],
];
}
Pre/Post-Generation Hooks
Use Laravel’s events:listen to run logic before/after file generation:
php artisan events:listen CustomMakeCommandGenerated,App\Listeners\PostModelGeneration
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']);
How can I help you explore Laravel packages today?