PHP code example of oneawebmarketing / console-awesome-table
1. Go to this page and download the library: Download oneawebmarketing/console-awesome-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/ */
oneawebmarketing / console-awesome-table example snippets
namespace App\Console\Commands;
use Illuminate\Console\Command;
use AwesomeTable\HasAwesomeTable;
class ShowUsers extends Command
{
use HasAwesomeTable;
protected $signature = 'demo:users';
protected $description = 'Show a list of users in an awesome table';
public function handle(): int
{
$this->title('Users');
$rows = [
['id' => 1, 'name' => 'Alice', 'email' => '[email protected]', 'gender' => 'FEMALE', 'age' => 42],
['id' => 2, 'name' => 'Bob', 'email' => '[email protected]', 'gender' => 'MALE', 'age' => 20],
];
// Headings provided explicitly, left over heading keys gets shown as info
$this->awesomeTable(
['id', 'name', 'email'],
$rows,
);
return self::SUCCESS;
}
}
$rows = [
['id' => 1, 'name' => 'Alice', 'address' => ['city' => 'Berlin', 'zip' => '10115']],
['id' => 2, 'name' => 'Bob', 'address' => ['city' => 'Hamburg', 'zip' => '20095']],
];
$this->awesomeTable(['id', 'name', 'address.city'], $rows);
$rows = [
['name' => 'Alice', 'tags' => ['admin', 'editor', '']],
['name' => 'Bob', 'tags' => ['viewer']],
];
$this->awesomeTable(['name', 'implode:tags'], $rows);
$rows = [
['name' => 'Alice', 'email' => '[email protected]'],
['name' => 'Bob', 'email' => '[email protected]'],
];
// Headings: ['name', 'email']
$this->awesomeTable([], $rows);
$rows = [
['id' => 1, 'name' => 'Alice', 'email' => '[email protected]', 'role' => 'admin'],
];
// Only "id", "name" and "email" shown in the table
$this->awesomeTable(['id', 'name', 'email'], $rows);
// Console (simplified):
// Undisplayed fields: role
bash
php artisan demo:users