Using table formatting in Artisan

Submitted by Azirius - 9 years ago

I happened across a function in Laravel's Command class. This command is Command::table(); Have you ever wanted to build a table in the same fashion that the 'routes' command does? Well, this function is how to do it! I couldn't find any real documentation on the method so just had a quick tinker with it and figured out it's usage. Here is an example of how to use it. Hopefully this might give the function some exposure, because at the moment, the web is lacking any!

$headers    =   ['id', 'email', 'Created At', 'Updated At'];
$users      =    User::all();

$this->table($headers, $users->toArray());