49 lines
1.5 KiB
PHP
Executable File
49 lines
1.5 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Console\Helper\Table;
|
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
|
|
|
class PermissionListCommand extends Command
|
|
{
|
|
protected static $defaultName = 'permission:list';
|
|
protected static $defaultDescription = 'Lista todas as permissões cadastradas no sistema';
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
if (!Capsule::schema()->hasTable('permissions')) {
|
|
$output->writeln('<error>Tabela de permissões não encontrada.</error>');
|
|
return Command::FAILURE;
|
|
}
|
|
|
|
$permissions = Capsule::table('permissions')
|
|
->orderBy('permission_name')
|
|
->get();
|
|
|
|
if ($permissions->isEmpty()) {
|
|
$output->writeln('<info>Nenhuma permissão encontrada.</info>');
|
|
return Command::SUCCESS;
|
|
}
|
|
|
|
$table = new Table($output);
|
|
$table->setHeaders(['ID', 'Nome', 'Slug', 'Descrição']);
|
|
|
|
foreach ($permissions as $permission) {
|
|
$table->addRow([
|
|
$permission->permission_id,
|
|
$permission->permission_name,
|
|
$permission->permission_slug,
|
|
$permission->permission_description ?? '-'
|
|
]);
|
|
}
|
|
|
|
$table->render();
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|