Skip to content
This repository was archived by the owner on Jul 16, 2021. It is now read-only.
This repository was archived by the owner on Jul 16, 2021. It is now read-only.

Make it possible to append rows to a rendered table in a console command. #2064

@freekmurze

Description

@freekmurze

Symfony provides a handy Table console helper that allows rows to be appended to an already rendered table.

Unfortunately, it's currently impossible to use this method in Laravel.

When newing up Symfony\Component\Console\Helper\Table it requires a ConsoleSectionOutput to be passed it.

A fully constructed ConsoleSectionOutput is available when calling section() on Symfony\Component\Console\Output\ConsoleOutputInterface. An object that implements this interface is available on Illuminate\Console\Command as $output. Unfortunately, this property is marked as protected.

In my project, I've just made this property public so I can just reach in and get the section.

// in a command

$section = $this->output->output->section();

$this->table = new Table($section);

$this->table->setHeaders(['Column', 'Another column']);
$this->table->render();

$this->table->appendRow(['Value', 'Another Value']);

I'm not advocating making this property public, but rather for an easy way to be able to use appendRow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions