From 82f90a0bcce2e35c6670e2524465e4debed772fb Mon Sep 17 00:00:00 2001 From: nosleepman1 Date: Sat, 11 Jul 2026 14:17:30 +0000 Subject: [PATCH] fix: rename package to nosleepman1/arch-cli, correct unique validation rule and pluralization getters --- README.fr.md | 4 ++-- README.md | 4 ++-- composer.json | 4 ++-- src/Generators/ControllerGenerator.php | 1 + src/Generators/RequestGenerator.php | 5 ++++- src/Generators/ServiceGenerator.php | 1 + src/Stubs/Controller.stub | 2 +- src/Stubs/Service.stub | 2 +- src/Stubs/ServiceWithRepository.stub | 2 +- tests/GenerateModuleCommandTest.php | 6 ++++-- 10 files changed, 19 insertions(+), 12 deletions(-) diff --git a/README.fr.md b/README.fr.md index 1a5909c..e6ce7fb 100644 --- a/README.fr.md +++ b/README.fr.md @@ -1,4 +1,4 @@ -# Arch CLI (nosleepman/module) +# Arch CLI (nosleepman1/arch-cli) Un package Laravel pour générer une architecture backend complète à partir de modèles métier. Ce package fournit des commandes artisan pour générer rapidement Modèles, Migrations, Contrôleurs, Services, Repositories, Policies, Événements, Écouteurs, Notifications et Ressources avec une seule commande. @@ -15,7 +15,7 @@ Veuillez consulter les guides détaillés pour des instructions d'utilisation co Installez le package via composer : ```bash -composer require nosleepman/module +composer require nosleepman1/arch-cli ``` Le "service provider" sera enregistré automatiquement. diff --git a/README.md b/README.md index 0727f43..367db5f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Arch CLI (nosleepman/module) +# Arch CLI (nosleepman1/arch-cli) A Laravel package to generate a complete backend architecture from business models. This package provides artisan commands to scaffold Models, Migrations, Controllers, Services, Repositories, Policies, Events, Listeners, Notifications, and Resources with a single command. @@ -15,7 +15,7 @@ Please refer to the detailed guides for complete usage instructions: Require the package via composer: ```bash -composer require nosleepman/module +composer require nosleepman1/arch-cli ``` The service provider will be automatically registered. diff --git a/composer.json b/composer.json index 53660f1..8a7eec7 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { - "name": "nosleepman/module", + "name": "nosleepman1/arch-cli", "replace": { - "nosleepman/arch-cli": "self.version" + "nosleepman1/arch-cli": "self.version" }, "description": "A Laravel package to generate complete backend architecture from business models", "type": "library", diff --git a/src/Generators/ControllerGenerator.php b/src/Generators/ControllerGenerator.php index 7bd675a..e81ecc0 100644 --- a/src/Generators/ControllerGenerator.php +++ b/src/Generators/ControllerGenerator.php @@ -13,6 +13,7 @@ public function generate(string $name, string $version, bool $withService): void $stub = $this->getStubContent($stubFile); $stub = str_replace('{{class}}', $name, $stub); + $stub = str_replace('{{pluralClass}}', \Illuminate\Support\Str::plural($name), $stub); $stub = str_replace('{{VERSION}}', strtoupper($version), $stub); $path = app_path('Http/Controllers/Api/' . strtoupper($version) . '/' . $name . 'Controller.php'); diff --git a/src/Generators/RequestGenerator.php b/src/Generators/RequestGenerator.php index 63540bf..935b9b8 100644 --- a/src/Generators/RequestGenerator.php +++ b/src/Generators/RequestGenerator.php @@ -7,10 +7,12 @@ class RequestGenerator { private $fields; + private $name; public function generate($name, $fields = '') { $this->fields = $fields; + $this->name = $name; $this->generateStoreRequest($name); $this->generateUpdateRequest($name); } @@ -57,6 +59,7 @@ private function generateRules($fields) { $fieldList = explode(',', $fields); $rules = ''; + $tableName = strtolower($this->name) . 's'; foreach ($fieldList as $field) { $parts = explode(':', trim($field)); @@ -78,7 +81,7 @@ private function generateRules($fields) foreach ($modifiers as $mod) { if ($mod === 'unique') { - $rule .= "|unique:{$fieldName}s"; + $rule .= "|unique:{$tableName},{$fieldName}"; } } diff --git a/src/Generators/ServiceGenerator.php b/src/Generators/ServiceGenerator.php index 8422f4d..1a4b540 100644 --- a/src/Generators/ServiceGenerator.php +++ b/src/Generators/ServiceGenerator.php @@ -15,6 +15,7 @@ public function generate(string $name, bool $withEvents = false, bool $withRepos $ServiceStub = str_replace('{{class}}', $name, $ServiceStub); $ServiceStub = str_replace('{{model}}', $name, $ServiceStub); + $ServiceStub = str_replace('{{pluralClass}}', \Illuminate\Support\Str::plural($name), $ServiceStub); if ($withEvents) { $ServiceStub = str_replace('{{use_events}}', 'use App\Events\\' . $name . 'Created;', $ServiceStub); diff --git a/src/Stubs/Controller.stub b/src/Stubs/Controller.stub index 75e6fcc..7798bdb 100644 --- a/src/Stubs/Controller.stub +++ b/src/Stubs/Controller.stub @@ -17,7 +17,7 @@ class {{class}}Controller extends Controller public function index(): JsonResponse { - return response()->json({{class}}Resource::collection($this->service->get{{class}}es())); + return response()->json({{class}}Resource::collection($this->service->get{{pluralClass}}())); } public function show(int $id): JsonResponse diff --git a/src/Stubs/Service.stub b/src/Stubs/Service.stub index 7558b97..000e946 100644 --- a/src/Stubs/Service.stub +++ b/src/Stubs/Service.stub @@ -17,7 +17,7 @@ class {{class}}Service return $model; } - public function get{{class}}es() + public function get{{pluralClass}}() { return {{model}}::all(); } diff --git a/src/Stubs/ServiceWithRepository.stub b/src/Stubs/ServiceWithRepository.stub index f1080a5..e8827b8 100644 --- a/src/Stubs/ServiceWithRepository.stub +++ b/src/Stubs/ServiceWithRepository.stub @@ -31,7 +31,7 @@ class {{class}}Service * * @return \Illuminate\Database\Eloquent\Collection */ - public function get{{class}}es() + public function get{{pluralClass}}() { return $this->repository->all(); } diff --git a/tests/GenerateModuleCommandTest.php b/tests/GenerateModuleCommandTest.php index 6a4ac44..9b0e727 100644 --- a/tests/GenerateModuleCommandTest.php +++ b/tests/GenerateModuleCommandTest.php @@ -88,24 +88,26 @@ public function test_it_generates_complete_module_with_service_and_repository() $this->assertStringContainsString('$this->repository->create($data)', $serviceContent); $this->assertStringContainsString('use App\Events\ProductCreated;', $serviceContent); $this->assertStringContainsString('event(new ProductCreated($model));', $serviceContent); + $this->assertStringContainsString('public function getProducts()', $serviceContent); // Assert Controller $controllerPath = app_path('Http/Controllers/Api/V1/ProductController.php'); $this->assertTrue(File::exists($controllerPath)); $controllerContent = File::get($controllerPath); $this->assertStringContainsString('protected ProductService $service', $controllerContent); + $this->assertStringContainsString('getProducts()', $controllerContent); // Assert Form Requests and dynamic validation rules $storeRequestPath = app_path('Http/Requests/Product/StoreProductRequest.php'); $this->assertTrue(File::exists($storeRequestPath)); $storeRequestContent = File::get($storeRequestPath); - $this->assertStringContainsString("'title' => 'required|string|max:255|unique:titles'", $storeRequestContent); + $this->assertStringContainsString("'title' => 'required|string|max:255|unique:products,title'", $storeRequestContent); $this->assertStringContainsString("'price' => 'required|integer'", $storeRequestContent); $updateRequestPath = app_path('Http/Requests/Product/UpdateProductRequest.php'); $this->assertTrue(File::exists($updateRequestPath)); $updateRequestContent = File::get($updateRequestPath); - $this->assertStringContainsString("'title' => 'required|string|max:255|unique:titles'", $updateRequestContent); + $this->assertStringContainsString("'title' => 'required|string|max:255|unique:products,title'", $updateRequestContent); // Assert API Resource $resourcePath = app_path('Http/Resources/ProductResource.php');