1. Go to this page and download the library: Download crumbls/laravel-cli-table library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
crumbls / laravel-cli-table example snippets
use Crumbls\LaravelCliTable\SelectableTable;
class YourCommand extends Command
{
public function handle()
{
$table = new SelectableTable($this->output);
$table->setHeaders(['ID', 'Name', 'Email']);
$table->setRows([
['1', 'John Doe', '[email protected]'],
['2', 'Jane Smith', '[email protected]'],
['3', 'Bob Johnson', '[email protected]'],
]);
// Interactive mode - returns selected row data
$selectedRow = $table->selectRow();
if ($selectedRow) {
$this->info("Selected: " . $selectedRow[1]); // John Doe, Jane Smith, etc.
}
}
}
// Set both colors at once
$table->setSelectedColors('green', 'white');
// Or set them individually
$table->setSelectedBackgroundColor('magenta');
$table->setSelectedForegroundColor('yellow');
// Available colors: black, red, green, yellow, blue, magenta, cyan, white
class SelectUserCommand extends Command
{
public function handle()
{
$users = User::all(['id', 'name', 'email', 'status']);
$table = new SelectableTable($this->output);
$table->setHeaders(['ID', 'Name', 'Email', 'Status'])
->setRows($users->toArray())
->setSelectedColors('blue', 'white');
$selected = $table->selectRow(function($row, $index) {
return User::find($row[0]);
});
if ($selected) {
$this->info("Selected user: {$selected->name}");
}
}
}
return [
'instructions' => 'Use ↑/↓ arrows to navigate, Enter to select, q/Esc to exit',
'selected_row' => 'Selected Row: :current/:total',
'selection_cancelled' => 'Selection cancelled',
// Add your own translations...
];