Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$this->table() Throws [InvalidArgumentException] A row must be an array or a TableSeparator instance

I've written a L4 Command class but the table output is throwing an exception.

<?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', '[email protected]', '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.

    }
}

Any ideas?

like image 228
Luke Avatar asked May 22 '17 11:05

Luke


1 Answers

You have to pass in an array of rows. Per table definition:

void table(array $headers, array $rows, string $style = 'default')

So you either do

$row = [['Luke', '[email protected]', '99']]; // An array of arrays, containing one row

or

$this->table($header, [$row]);
like image 104
Coloured Panda Avatar answered Oct 15 '22 04:10

Coloured Panda