Installation Add the package via Composer:
composer require alexeyshockov/plain-commands
(Note: Since the package is archived, verify compatibility with your Laravel version.)
Basic Command Definition
Create a command class in app/Console/Commands:
use Alexeyshockov\PlainCommands\Command;
class ExampleCommand extends Command
{
protected $name = 'example:greet';
protected $description = 'Greets the user';
public function handle()
{
$this->info('Hello, Laravel!');
}
}
Register the Command
Add the command to app/Console/Kernel.php:
protected $commands = [
\App\Console\Commands\ExampleCommand::class,
];
Run the Command Execute via Artisan:
php artisan example:greet
Use this package to rapidly scaffold CLI tools without boilerplate. Ideal for:
queue:flush-all).Leverage the Command base class for consistency:
class MyCommand extends Command
{
// Required: Command name (e.g., 'app:process')
protected $name = 'app:process';
// Required: Description (shown in `artisan list`)
protected $description = 'Processes X';
// Optional: Arguments/options
protected $arguments = [
['input', InputArgument::REQUIRED, 'Input file path'],
];
protected $options = [
['force', 'f', InputOption::VALUE_NONE, 'Force overwrite'],
];
public function handle()
{
$input = $this->argument('input');
$force = $this->option('force');
// Business logic here
}
}
Use Symfony’s Console components via $this:
// Output
$this->info('Success!');
$this->error('Failed!');
$this->question('Confirm?', 'y');
// Input
$name = $this->ask('Enter name');
$confirm = $this->confirm('Proceed?', false);
Inject services via Laravel’s container:
public function __construct(MyService $service)
{
$this->service = $service;
}
Organize commands with namespaces:
// Command name: `app:user:create`
protected $name = 'app:user:create';
Run all app:user:* commands with:
php artisan app:user
Trigger Laravel events from commands:
event(new UserCreated($user));
Test commands via Artisan::call():
$exitCode = Artisan::call('example:greet');
$this->assertEquals(0, $exitCode);
Archived Package Risk
No Built-in Scheduling
Schedule, this package doesn’t integrate with app/Console/Kernel.php's $schedule. Use Laravel’s native scheduling instead.Limited Validation
Validator or Symfony’s ValidatorInterface.Namespace Collisions
cache:clear). Prefix with your app name (e.g., app:cache:clear).$this->verbose('Debug info') for detailed logs.return 1; // Fails the command
Custom Helpers Extend the base class for shared logic:
class BaseCommand extends Command
{
protected function log($message) { /* ... */ }
}
Input Validation
Reuse Laravel’s Validator:
$validator = Validator::make(['name' => $this->argument('name')], ['name' => 'required|string']);
Interactive Prompts Chain methods for complex workflows:
$name = $this->ask('Name');
$confirm = $this->confirm(sprintf('Create %s?', $name));
Configuration
Load config via Laravel’s config() helper:
$timeout = config('app.command_timeout');
Cache facade to avoid repeated I/O:
public function __construct(Cache $cache) { /* ... */ }
How can I help you explore Laravel packages today?