Files
2026-09-01 10:46:29 -03:00

55 lines
1.7 KiB
PHP
Executable File

<?php
namespace App\Console\Commands;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Illuminate\Database\Capsule\Manager as Capsule;
use Symfony\Component\Console\Helper\Table;
class DbTableCommand extends Command
{
protected static $defaultName = 'db:table';
protected static $defaultDescription = 'Exibe a estrutura de uma tabela específica';
protected function configure(): void
{
$this
->addArgument('table', InputArgument::REQUIRED, 'O nome da tabela');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$tableName = $input->getArgument('table');
$connection = Capsule::connection();
try {
$columns = $connection->select("SHOW COLUMNS FROM {$tableName}");
$output->writeln("<info>Estrutura da tabela: {$tableName}</info>");
$table = new Table($output);
$table->setHeaders(['Field', 'Type', 'Null', 'Key', 'Default', 'Extra']);
foreach ($columns as $column) {
$table->addRow([
$column->Field,
$column->Type,
$column->Null,
$column->Key,
$column->Default,
$column->Extra
]);
}
$table->render();
return Command::SUCCESS;
} catch (\Exception $e) {
$output->writeln("<error>Tabela '{$tableName}' não encontrada ou erro na query.</error>");
return Command::FAILURE;
}
}
}