我已经编写了L4 Command类,但table
输出正在抛出异常。
<?php
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class Table extends Command {
protected $name = 'table';
public function fire()
{
//output table;
$header = ['Name', 'Email', 'Age'];
$row = ['Luke', 'me@email.uk', '99'];
$this->info(sprintf("is array ? %s", is_array($row) ? 'true' : 'false'));
//outputs is array ? true
$this->table($header, $row);
//throws exception
// [InvalidArgumentException]
// A row must be an array or a TableSeparator instance.
}
}
有什么想法吗?
答案 0 :(得分:5)
您必须传入一组行。每table
个定义:
void table(array $headers, array $rows, string $style = 'default')
所以你要么
$row = [['Luke', 'me@email.uk', '99']]; // An array of arrays, containing one row
或
$this->table($header, [$row]);