我已经编写了一个 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.
}
}
有什么想法吗?
最佳答案
您必须传入行数组。根据 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]);
关于laravel - $this->table() 抛出 [InvalidArgumentException] 行必须是数组或 TableSeparator 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44111318/