argument('name'); $studlyName = Str::studly($name); $kebabName = Str::kebab($name); $modulePath = app_path("Modules/{$studlyName}"); if (File::exists($modulePath)) { $this->error("Module {$studlyName} already exists!"); return self::FAILURE; } $this->info("Creating module: {$studlyName}"); $this->createDirectories($modulePath); $this->createModel($modulePath, $studlyName); $this->createMigration($studlyName); $this->createController($modulePath, $studlyName); $this->createRoutes($modulePath, $studlyName, $kebabName); $this->createViews($modulePath, $studlyName, $kebabName); $this->createFilamentResource($studlyName); $this->createTests($studlyName); $this->info("\n✅ Module {$studlyName} created successfully!"); $this->info("\nNext steps:"); $this->info("1. Run migrations: php artisan migrate"); $this->info("2. Register routes in routes/web.php:"); $this->info(" require __DIR__.'/../app/Modules/{$studlyName}/routes.php';"); $this->info("3. Access at: /{$kebabName}"); return self::SUCCESS; } protected function createDirectories(string $path): void { File::makeDirectory($path, 0755, true); File::makeDirectory("{$path}/Models", 0755, true); File::makeDirectory("{$path}/Controllers", 0755, true); File::makeDirectory("{$path}/Views", 0755, true); } protected function createModel(string $path, string $name): void { $stub = <<info("✓ Created Model: {$name}"); } protected function createMigration(string $name): void { $table = Str::snake(Str::plural($name)); $timestamp = date('Y_m_d_His'); $migrationName = "create_{$table}_table"; $stub = <<id(); \$table->string('name'); \$table->text('description')->nullable(); \$table->timestamps(); }); } public function down(): void { Schema::dropIfExists('{$table}'); } }; PHP; $migrationPath = database_path("migrations/{$timestamp}_{$migrationName}.php"); File::put($migrationPath, $stub); $this->info("✓ Created Migration: {$migrationName}"); } protected function createController(string $path, string $name): void { $plural = Str::plural($name); $variable = Str::camel($name); $pluralVariable = Str::camel($plural); $stub = <<paginate(15); return view('{$name}::index', compact('{$pluralVariable}')); } public function create() { return view('{$name}::create'); } public function store(Request \$request) { \$validated = \$request->validate([ 'name' => 'required|string|max:255', 'description' => 'nullable|string', ]); {$name}::create(\$validated); return redirect()->route('{$variable}.index') ->with('success', '{$name} created successfully.'); } public function show({$name} \${$variable}) { return view('{$name}::show', compact('{$variable}')); } public function edit({$name} \${$variable}) { return view('{$name}::edit', compact('{$variable}')); } public function update(Request \$request, {$name} \${$variable}) { \$validated = \$request->validate([ 'name' => 'required|string|max:255', 'description' => 'nullable|string', ]); \${$variable}->update(\$validated); return redirect()->route('{$variable}.index') ->with('success', '{$name} updated successfully.'); } public function destroy({$name} \${$variable}) { \${$variable}->delete(); return redirect()->route('{$variable}.index') ->with('success', '{$name} deleted successfully.'); } } PHP; File::put("{$path}/Controllers/{$name}Controller.php", $stub); $this->info("✓ Created Controller: {$name}Controller"); } protected function createRoutes(string $path, string $name, string $kebabName): void { $variable = Str::camel($name); $stub = <<group(function () { Route::resource('{$kebabName}', {$name}Controller::class)->names('{$variable}'); }); PHP; File::put("{$path}/routes.php", $stub); $this->info("✓ Created Routes"); } protected function createViews(string $path, string $name, string $kebabName): void { $plural = Str::plural($name); $variable = Str::camel($name); $pluralVariable = Str::camel($plural); $indexView = <<

{{ __('{$plural}') }}

{$plural} List

Create New
@if(session('success'))
{{ session('success') }}
@endif @forelse(\${$pluralVariable} as \${$variable}) @empty @endforelse
Name Description Actions
{{ \${$variable}->name }} {{ \${$variable}->description }} Edit
@csrf @method('DELETE')
No {$pluralVariable} found.
{{ \${$pluralVariable}->links() }}
BLADE; File::put("{$path}/Views/index.blade.php", $indexView); $this->info("✓ Created Views"); } protected function createFilamentResource(string $name): void { $this->call('make:filament-resource', [ 'name' => $name, '--generate' => true, ]); } protected function createTests(string $name): void { $variable = Str::camel($name); $stub = <<create(); {$name}::factory()->count(3)->create(); \$response = \$this->actingAs(\$user)->get(route('{$variable}.index')); \$response->assertStatus(200); }); it('can create {$variable}', function () { \$user = User::factory()->create(); \$response = \$this->actingAs(\$user)->post(route('{$variable}.store'), [ 'name' => 'Test {$name}', 'description' => 'Test description', ]); \$response->assertRedirect(route('{$variable}.index')); \$this->assertDatabaseHas('{$variable}s', ['name' => 'Test {$name}']); }); PHP; $testPath = base_path("tests/Modules/{$name}"); File::makeDirectory($testPath, 0755, true); File::put("{$testPath}/{$name}Test.php", $stub); $this->info("✓ Created Tests"); } }