Files
2026-07-24 14:59:44 +01:00

38 lines
1.2 KiB
PHP

<?php
namespace Modules\Developer\Console\Commands;
use Illuminate\Console\Command;
use Modules\Developer\Support\CrudGenerator;
use Throwable;
final class MakeCrudCommand extends Command
{
protected $signature = 'crud:make {model} {--module=} {--force}';
protected $description = 'Generate model, migration, request, controller, views and test inside a module.';
public function handle(CrudGenerator $generator): int
{
$module = $this->option('module') ?: $this->choice('Select the target module', $this->modules());
try {
$files = $generator->generate((string) $module, $this->argument('model'), (bool) $this->option('force'));
} catch (Throwable $e) {
$this->error($e->getMessage());
return self::FAILURE;
}
foreach ($files as $file) {
$this->line("<info>created</info> {$file}");
}
$this->warn('Register the generated controller routes in the target module Routes/web.php file.');
return self::SUCCESS;
}
private function modules(): array
{
return collect(glob(base_path('Modules/*/module.json')) ?: [])->map(fn (string $file) => basename(dirname($file)))->sort()->values()->all();
}
}