laravel-zero/framework
Laravel Zero is an unofficial, Laravel-based micro-framework for building fast, elegant console apps. Includes optional Eloquent/logging, interactive menus, desktop notifications, scheduler, standalone compiler, and Collision-powered error reporting.
Installation:
composer require laravel-zero/framework
For a new project, use the installer:
composer create-project laravel-zero/laravel-zero my-cli-app
First Command:
Create a command in app/Console/Commands/ (e.g., HelloCommand.php):
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class HelloCommand extends Command
{
protected $signature = 'hello {name?}';
protected $description = 'Say hello to someone';
public function handle()
{
$name = $this->argument('name') ?: 'World';
$this->info("Hello, {$name}!");
}
}
Run it:
php artisan hello John
Key Files to Explore:
app/Console/Kernel.php: Command registration.config/console.php: CLI-specific configuration.artisan: The CLI entry point (customizable via app/Console/Kernel.php).Command Development:
protected $signature = 'task:run {--force} {--queue=}';
protected $description = 'Run a scheduled task';
$this->argument() or $this->option().$this->info(), $this->error(), or $this->table() for structured output.Interactive Menus:
Use laravel-zero/menu for CLI menus:
use LaravelZero\Framework\Menu;
$menu = Menu::new()
->title('Main Menu')
->option('Backup', fn() => $this->call('backup:run'))
->option('Cleanup', fn() => $this->call('cleanup:temp'))
->action();
Task Scheduling:
Define tasks in app/Console/Kernel.php:
protected function schedule(Schedule $schedule)
{
$schedule->command('backup:run')->daily();
}
Run with:
php artisan schedule:run
PHAR Compilation: Build a standalone binary:
php artisan build
Customize via php artisan build --help.
Configuration:
Share settings across commands via config/console.php or environment variables.
laravel/prompts for user input:
use Laravel\Prompts\Prompt;
$name = Prompt::anticipate('What is your name?', ['John', 'Jane']);
nunomaduro/collision for rich error reporting:
use Collision\Collision;
Collision::handle(function () {
throw new \RuntimeException('Something went wrong!');
});
PHAR Limitations:
class_alias) or eval() in PHARs.composer dump-autoload --optimize.Command Registration:
app/Console/Commands/ must extend Illuminate\Console\Command (or LaravelZero\Framework\Commands\Command).Kernel.php makes them invisible to artisan.Configuration Conflicts:
config/console.php carefully; some keys (e.g., name) are critical for PHAR builds.config_path() to dynamically load configs if needed.Scheduler Quirks:
artisan schedule:run. For cron jobs, use:
* * * * * cd /path-to-project && php artisan schedule:run >> /dev/null 2>&1
PHAR Debugging:
php artisan build --debug
bootstrap/app.php for PHAR-specific overrides.Enable Debug Mode:
php artisan --env=local
Or set APP_DEBUG=true in .env.
Log Output:
Use ->debug() or ->line() for verbose logging. Check storage/logs/laravel.log.
Collision Errors:
Ensure nunomaduro/collision is installed and configured in config/collision.php.
PHAR Issues:
stub in bootstrap/app.php matches your needs.php artisan build --verbose to see compilation steps.Custom Artisan Commands:
Extend LaravelZero\Framework\Commands\Command for shared CLI logic (e.g., auth, logging).
Menu Customization:
Override LaravelZero\Framework\Menu to add themes or dynamic options.
PHAR Hooks:
Use BootstrapServiceProvider in config/app.php to modify PHAR behavior:
'providers' => [
// ...
App\Providers\BootstrapServiceProvider::class,
],
Prompts Integration: Bind custom prompts to commands:
$this->call('prompt:custom', [
'--question' => 'Confirm action?',
'--default' => 'yes',
]);
Scheduler Extensions:
Add custom schedule events by extending Illuminate\Console\Scheduling\Schedule.
How can I help you explore Laravel packages today?