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

I wrote an L4 Command class, but the output is table

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', '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.

    }
}

      

Any ideas?

+3


source to share


1 answer


You need to pass an array of strings. Per table

:

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

      

So you either do



$row = [['Luke', 'me@email.uk', '99']]; // An array of arrays, containing one row

      

or

$this->table($header, [$row]);

      

+4


source







All Articles