azizizaidi/laravel-all-in-one-command
Scaffold a complete Laravel feature with one artisan command. Interactively generate CRUD essentials: model, migration, factory, seeder, controllers, form requests, services (optional interface), policies, web/API routes, tests, scheduled command, and Blade views.
Installation:
composer require azizizaidi/laravel-all-in-one-command
Publish the config file (if needed):
php artisan vendor:publish --provider="Azizizaidi\AllInOneCommand\AllInOneCommandServiceProvider"
First Use Case:
Register the command in app/Console/Kernel.php:
protected function commands()
{
$this->load(__DIR__.'/../vendor/azizizaidi/laravel-all-in-one-command/src/Console');
}
Run the command:
php artisan all:in-one
Where to Look First:
config/all-in-one-command.php (if published) for customization.vendor/azizizaidi/laravel-all-in-one-command/src/Console/AllInOneCommand.php to understand core logic.Customizing Command Output:
Override the handle() method in a custom command extending AllInOneCommand:
namespace App\Console\Commands;
use Azizizaidi\AllInOneCommand\AllInOneCommand as BaseCommand;
class CustomCommand extends BaseCommand
{
protected $signature = 'custom:command';
protected $description = 'My custom command';
public function handle()
{
$this->info('Running custom logic...');
// Extend base functionality
parent::handle();
}
}
Integrating with Laravel Artisan Events:
Listen to the command's events (e.g., all-in-one-starting, all-in-one-completed) in EventServiceProvider:
protected $listen = [
'all-in-one-starting' => [
\App\Listeners\LogCommandStart::class,
],
];
Chaining Commands:
Use the --chain flag to run multiple commands sequentially:
php artisan all:in-one --chain="migrate,optimize,queue:work"
Dynamic Command Generation: Dynamically generate commands based on environment variables or config:
$commands = config('all-in-one-command.dynamic_commands', []);
foreach ($commands as $command) {
$this->call($command);
}
dispatch() or dispatchSync() for long-running tasks.\Log::) for command output.Artisan::call():
$this->artisan('all:in-one')
->expectsQuestion('Confirm?', 'yes')
->assertExitCode(0);
Command Signature Conflicts:
Avoid naming custom commands with the same signature as Laravel's built-in commands (e.g., optimize). Use unique namespaces or prefixes.
Overriding Core Logic:
If extending AllInOneCommand, ensure parent::handle() is called to retain base functionality unless intentional.
Environment-Specific Behavior:
The package may not handle environment-specific logic out of the box. Use Laravel's config() or env() helpers to manage this:
if (app()->environment('local')) {
$this->call('key:generate');
}
Performance with Large Command Chains:
Long chains of commands (e.g., migrate:fresh --seed) may time out. Use --timeout or split into smaller batches.
-v or -vvv for detailed logs:
php artisan all:in-one -vvv
php artisan migrate --pretend
telescope:install to debug events if the package emits them.Custom Commands:
Create a Console/Commands directory in your app and register commands in Kernel.php:
$this->load(__DIR__.'/Commands');
Middleware:
Apply middleware to commands via the handle() method:
public function handle()
{
$this->middleware(CheckEnvironment::class);
parent::handle();
}
Configuration Overrides:
Override defaults in config/all-in-one-command.php:
'default_commands' => [
'migrate',
'optimize',
'route:clear',
],
Localization:
Extend language files in resources/lang/{locale}/all-in-one-command.php for custom messages.
How can I help you explore Laravel packages today?