From 696e158edd901538775209f0ba952435b2b56993 Mon Sep 17 00:00:00 2001 From: Fady Mondy Date: Sat, 22 Jun 2024 16:41:32 +0300 Subject: [PATCH] Generate Models, Resource... #13 --- src/Services/Concerns/GenerateCasts.php | 2 +- src/Services/Concerns/GenerateController.php | 42 +++++++++---------- src/Services/Concerns/GenerateFolders.php | 14 +++---- src/Services/Concerns/GenerateFormView.php | 6 +-- .../Concerns/GenerateJsonResource.php | 6 +-- src/Services/Concerns/GenerateMenus.php | 2 +- src/Services/Concerns/GenerateRequest.php | 16 +++---- src/Services/Concerns/GenerateRoutes.php | 8 ++-- src/Services/Concerns/GenerateTable.php | 8 ++-- 9 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/Services/Concerns/GenerateCasts.php b/src/Services/Concerns/GenerateCasts.php index 5b07cb7..16c0f01 100644 --- a/src/Services/Concerns/GenerateCasts.php +++ b/src/Services/Concerns/GenerateCasts.php @@ -7,7 +7,7 @@ trait GenerateCasts private function generateCasts() { $this->injectString( - $this->moduleName ? module_path($this->moduleName) ."/App/Models/{$this->modelName}.php" : app_path("Models/{$this->modelName}.php"), + $this->moduleName ? module_path($this->moduleName) ."/app/Models/{$this->modelName}.php" : app_path("Models/{$this->modelName}.php"), 'protected $fillable =', $this->stubPath . "casts.stub", [ diff --git a/src/Services/Concerns/GenerateController.php b/src/Services/Concerns/GenerateController.php index 6d41c7a..eb926c1 100644 --- a/src/Services/Concerns/GenerateController.php +++ b/src/Services/Concerns/GenerateController.php @@ -9,7 +9,7 @@ trait GenerateController { private function generateController(bool $isForce = false) { - $filePath = $this->moduleName ? module_path($this->moduleName) ."/App/Http/Controllers/{$this->modelName}Controller.php" : app_path("Http/Controllers/Admin/{$this->modelName}Controller.php"); + $filePath = $this->moduleName ? module_path($this->moduleName) ."/app/Http/Controllers/{$this->modelName}Controller.php" : app_path("Http/Controllers/Admin/{$this->modelName}Controller.php"); if($isForce){ if(File::exists($filePath)){ File::delete($filePath); @@ -17,21 +17,21 @@ private function generateController(bool $isForce = false) } $this->generateStubs( $this->stubPath . "controller.stub", - $this->moduleName ? module_path($this->moduleName) ."/App/Http/Controllers/{$this->modelName}Controller.php" : app_path("Http/Controllers/Admin/{$this->modelName}Controller.php"), + $this->moduleName ? module_path($this->moduleName) ."/app/Http/Controllers/{$this->modelName}Controller.php" : app_path("Http/Controllers/Admin/{$this->modelName}Controller.php"), [ "name" => "{$this->modelName}Controller", - "model" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Models\\".$this->modelName : "\\App\\Models\\".$this->modelName, + "model" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\Models\\".$this->modelName : "\\App\\Models\\".$this->modelName, "title" => $this->modelName, "table" => str_replace('_', '-', $this->tableName), "validation" => $this->generateRules(), "validationEdit" => $this->generateRules(true), - "requestNamespace" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Http\\Requests\\{$this->modelName}\\" : "\\App\\Http\\Requests\\Admin\\{$this->modelName}\\", - "tableClass" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Tables\\".$this->modelName."Table" : "\\App\\Tables\\".$this->modelName."Table", - "namespace" => $this->moduleName ? "Modules\\".$this->moduleName."\\App\\Http\\Controllers": "App\\Http\\Controllers\\Admin", + "requestNamespace" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\Http\\Requests\\{$this->modelName}\\" : "\\App\\Http\\Requests\\Admin\\{$this->modelName}\\", + "tableClass" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\Tables\\".$this->modelName."Table" : "\\App\\Tables\\".$this->modelName."Table", + "namespace" => $this->moduleName ? "Modules\\".$this->moduleName."\\Http\\Controllers": "App\\Http\\Controllers\\Admin", "modulePath" => $this->moduleName ? Str::replace('_', '-', Str::lower($this->moduleName))."::" : "admin." ], [ - $this->moduleName ? module_path($this->moduleName) ."/App/Http/Controllers/" : app_path("Http/Controllers/Admin") + $this->moduleName ? module_path($this->moduleName) ."/app/Http/Controllers/" : app_path("Http/Controllers/Admin") ] ); } @@ -40,19 +40,19 @@ private function generateControllerForRequest() { $this->generateStubs( $this->stubPath . "controller-request.stub", - $this->moduleName ? module_path($this->moduleName) ."/App/Http/Controllers/{$this->modelName}Controller.php" : app_path("Http/Controllers/Admin/{$this->modelName}Controller.php"), + $this->moduleName ? module_path($this->moduleName) ."/app/Http/Controllers/{$this->modelName}Controller.php" : app_path("Http/Controllers/Admin/{$this->modelName}Controller.php"), [ "name" => "{$this->modelName}Controller", - "model" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Models\\".$this->modelName : "\\App\\Models\\".$this->modelName, + "model" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\Models\\".$this->modelName : "\\App\\Models\\".$this->modelName, "title" => $this->modelName, "table" => str_replace('_', '-', $this->tableName), - "requestNamespace" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Http\\Requests\\{$this->modelName}\\" : "\\App\\Http\\Requests\\Admin\\{$this->modelName}\\", - "tableClass" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Tables\\".$this->modelName."Table" : "\\App\\Tables\\".$this->modelName."Table", - "namespace" => $this->moduleName ? "Modules\\".$this->moduleName."\\App\\Http\\Controllers": "App\\Http\\Controllers\\Admin", + "requestNamespace" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\Http\\Requests\\{$this->modelName}\\" : "\\App\\Http\\Requests\\Admin\\{$this->modelName}\\", + "tableClass" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\Tables\\".$this->modelName."Table" : "\\App\\Tables\\".$this->modelName."Table", + "namespace" => $this->moduleName ? "Modules\\".$this->moduleName."\\Http\\Controllers": "App\\Http\\Controllers\\Admin", "modulePath" => $this->moduleName ? Str::replace('_', '-', Str::lower($this->moduleName))."::" : "admin." ], [ - $this->moduleName ? module_path($this->moduleName) ."/App/Http/Controllers/" : app_path("Http/Controllers/Admin") + $this->moduleName ? module_path($this->moduleName) ."/app/Http/Controllers/" : app_path("Http/Controllers/Admin") ] ); } @@ -61,23 +61,23 @@ private function generateControllerForBuilder() { $this->generateStubs( $this->stubPath ."FormBuilder/BuilderController.stub", - $this->moduleName ? module_path($this->moduleName) ."/App/Http/Controllers/{$this->modelName}Controller.php" : app_path("Http/Controllers/Admin/{$this->modelName}Controller.php"), + $this->moduleName ? module_path($this->moduleName) ."/app/Http/Controllers/{$this->modelName}Controller.php" : app_path("Http/Controllers/Admin/{$this->modelName}Controller.php"), [ "name" => "{$this->modelName}Controller", - "model" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Models\\".$this->modelName : "\\App\\Models\\".$this->modelName, + "model" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\Models\\".$this->modelName : "\\App\\Models\\".$this->modelName, "title" => $this->modelName, "table" => str_replace('_', '-', $this->tableName), "validation" => $this->generateRules(), "validationEdit" => $this->generateRules(true), - "formClass" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Forms\\{$this->modelName}Form" : "\\App\\Forms\\{$this->modelName}Form", - "requestNamespace" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Http\\Requests\\{$this->modelName}\\" : "\\App\\Http\\Requests\\Admin\\{$this->modelName}\\", - "FormNamespace" => $this->moduleName ? "Modules\\".$this->moduleName."\\App\\Forms\\{$this->modelName}Form" : "App\\Forms\\{$this->modelName}Form", - "tableClass" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Tables\\".$this->modelName."Table" : "\\App\\Tables\\".$this->modelName."Table", - "namespace" => $this->moduleName ? "Modules\\".$this->moduleName."\\App\\Http\\Controllers": "App\\Http\\Controllers\\Admin", + "formClass" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\Forms\\{$this->modelName}Form" : "\\App\\Forms\\{$this->modelName}Form", + "requestNamespace" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\Http\\Requests\\{$this->modelName}\\" : "\\App\\Http\\Requests\\Admin\\{$this->modelName}\\", + "FormNamespace" => $this->moduleName ? "Modules\\".$this->moduleName."\\Forms\\{$this->modelName}Form" : "App\\Forms\\{$this->modelName}Form", + "tableClass" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\Tables\\".$this->modelName."Table" : "\\App\\Tables\\".$this->modelName."Table", + "namespace" => $this->moduleName ? "Modules\\".$this->moduleName."\\Http\\Controllers": "App\\Http\\Controllers\\Admin", "modulePath" => $this->moduleName ? Str::replace('_', '-', Str::lower($this->moduleName))."::" : "admin." ], [ - $this->moduleName ? module_path($this->moduleName) ."/App/Http/Controllers/" : app_path("Http/Controllers/Admin") + $this->moduleName ? module_path($this->moduleName) ."/app/Http/Controllers/" : app_path("Http/Controllers/Admin") ] ); } diff --git a/src/Services/Concerns/GenerateFolders.php b/src/Services/Concerns/GenerateFolders.php index 04dc446..a1448ad 100644 --- a/src/Services/Concerns/GenerateFolders.php +++ b/src/Services/Concerns/GenerateFolders.php @@ -11,15 +11,15 @@ private function generateFolders(): void { if($this->moduleName){ $folders = [ - module_path($this->moduleName) ."/App/Http/Controllers/", - module_path($this->moduleName) ."/App/resources/", - module_path($this->moduleName) ."/App/Http/Requests/", - module_path($this->moduleName) ."/App/Http/Requests/{$this->modelName}", - module_path($this->moduleName) ."/App/Models/", + module_path($this->moduleName) ."/app/Http/Controllers/", + module_path($this->moduleName) ."/app/resources/", + module_path($this->moduleName) ."/app/Http/Requests/", + module_path($this->moduleName) ."/app/Http/Requests/{$this->modelName}", + module_path($this->moduleName) ."/app/Models/", module_path($this->moduleName) . "/resources/views/" . str_replace('_', '-', $this->tableName), module_path($this->moduleName) . "/routes", - module_path($this->moduleName)."/App/Tables", - module_path($this->moduleName)."/App/Forms", + module_path($this->moduleName)."/app/Tables", + module_path($this->moduleName)."/app/Forms", ]; } else { diff --git a/src/Services/Concerns/GenerateFormView.php b/src/Services/Concerns/GenerateFormView.php index 93aa125..86d3f87 100644 --- a/src/Services/Concerns/GenerateFormView.php +++ b/src/Services/Concerns/GenerateFormView.php @@ -33,15 +33,15 @@ private function generateFormBuilderClass() { $this->generateStubs( $this->stubPath ."FormBuilder/FormClass.stub", - $this->moduleName ? module_path($this->moduleName) . "/App/Forms/{$this->modelName}Form.php" : app_path("Forms/{$this->modelName}Form.php"), + $this->moduleName ? module_path($this->moduleName) . "/app/Forms/{$this->modelName}Form.php" : app_path("Forms/{$this->modelName}Form.php"), [ "name" => "{$this->modelName}Form", "route" => str_replace('_', '-', $this->tableName), "cols" => $this->generateFormElements(), - "namespace" => $this->moduleName ? "Modules\\" . $this->moduleName . "\\App\\Forms" : "App\\Forms", + "namespace" => $this->moduleName ? "Modules\\" . $this->moduleName . "\\Forms" : "App\\Forms", ], [ - $this->moduleName ? module_path($this->moduleName) . "/App/Forms" : app_path("Forms") + $this->moduleName ? module_path($this->moduleName) . "/app/Forms" : app_path("Forms") ] ); } diff --git a/src/Services/Concerns/GenerateJsonResource.php b/src/Services/Concerns/GenerateJsonResource.php index 066b8da..a7499f5 100644 --- a/src/Services/Concerns/GenerateJsonResource.php +++ b/src/Services/Concerns/GenerateJsonResource.php @@ -12,7 +12,7 @@ private function generateJsonResource(): void $folders = []; $resourceName = Str::of($this->tableName)->replace('_', ' ')->camel()->ucfirst()->toString() . 'Resource'; if($this->moduleName){ - $folders[] = module_path($this->moduleName) . "/App/resources"; + $folders[] = module_path($this->moduleName) . "/app/Http/Resources"; } else { $folders[] = app_path("Http/Resources"); @@ -20,9 +20,9 @@ private function generateJsonResource(): void $this->generateStubs( $this->stubPath . "json.stub", - $this->moduleName ? module_path($this->moduleName) . "/App/resources/" . $resourceName . '.php' : app_path("Http/Resources/" . $resourceName . '.php'), + $this->moduleName ? module_path($this->moduleName) . "/app/resources/" . $resourceName . '.php' : app_path("Http/Resources/" . $resourceName . '.php'), [ - "namespace" => $this->moduleName ? "Modules\\".$this->moduleName."\\App\\resources" : "App\\Http\\Resources", + "namespace" => $this->moduleName ? "Modules\\".$this->moduleName."\\Http\\Resources" : "App\\Http\\Resources", "name" => $resourceName, "fields" => $this->generateFields(), "table" => str_replace('_', '-', $this->tableName), diff --git a/src/Services/Concerns/GenerateMenus.php b/src/Services/Concerns/GenerateMenus.php index dd54aba..4a57317 100644 --- a/src/Services/Concerns/GenerateMenus.php +++ b/src/Services/Concerns/GenerateMenus.php @@ -7,7 +7,7 @@ trait GenerateMenus private function generateMenus() { $this->injectString( - $this->moduleName ? module_path($this->moduleName) ."/App/Providers/{$this->moduleName}ServiceProvider.php" : app_path("Providers/AppServiceProvider.php"), + $this->moduleName ? module_path($this->moduleName) ."/app/Providers/{$this->moduleName}ServiceProvider.php" : app_path("Providers/AppServiceProvider.php"), $this->moduleName ? '$this->loadMigrationsFrom(module_path($this->moduleName, \'Database/migrations\'));' : 'public function boot(): void', $this->stubPath . "menu.stub", [ diff --git a/src/Services/Concerns/GenerateRequest.php b/src/Services/Concerns/GenerateRequest.php index 0f49cc3..33eabc8 100644 --- a/src/Services/Concerns/GenerateRequest.php +++ b/src/Services/Concerns/GenerateRequest.php @@ -12,31 +12,31 @@ private function generateRequest(): void { $this->generateStubs( $this->stubPath . "request.stub", - $this->moduleName ? module_path($this->moduleName) ."/App/Http/Requests/{$this->modelName}/{$this->modelName}StoreRequest.php" : app_path("Http/Requests/Admin/{$this->modelName}/{$this->modelName}StoreRequest.php"), + $this->moduleName ? module_path($this->moduleName) ."/app/Http/Requests/{$this->modelName}/{$this->modelName}StoreRequest.php" : app_path("Http/Requests/Admin/{$this->modelName}/{$this->modelName}StoreRequest.php"), [ "name" => "{$this->modelName}StoreRequest", "model" => $this->modelName, "validation" => $this->generateRules(), - "namespace" => $this->moduleName ? "Modules\\{$this->moduleName}\\App\\Http\\Requests\\{$this->modelName}" : "App\\Http\\Requests\\Admin\\{$this->modelName}", + "namespace" => $this->moduleName ? "Modules\\{$this->moduleName}\\Http\\Requests\\{$this->modelName}" : "App\\Http\\Requests\\Admin\\{$this->modelName}", ], [ - $this->moduleName ? module_path($this->moduleName) ."/App/Http/Requests": app_path("Http/Requests/Admin"), - $this->moduleName ? module_path($this->moduleName) ."/App/Http/Requests/{$this->modelName}": app_path("Http/Requests/Admin/{$this->modelName}"), + $this->moduleName ? module_path($this->moduleName) ."/app/Http/Requests": app_path("Http/Requests/Admin"), + $this->moduleName ? module_path($this->moduleName) ."/app/Http/Requests/{$this->modelName}": app_path("Http/Requests/Admin/{$this->modelName}"), ] ); $this->generateStubs( $this->stubPath . "request.stub", - $this->moduleName ? module_path($this->moduleName)."/App/Http/Requests/{$this->modelName}/{$this->modelName}UpdateRequest.php" : app_path("Http/Requests/Admin/{$this->modelName}/{$this->modelName}UpdateRequest.php"), + $this->moduleName ? module_path($this->moduleName)."/app/Http/Requests/{$this->modelName}/{$this->modelName}UpdateRequest.php" : app_path("Http/Requests/Admin/{$this->modelName}/{$this->modelName}UpdateRequest.php"), [ "name" => "{$this->modelName}UpdateRequest", "model" => $this->modelName, "validation" => $this->generateRules(true), - "namespace" => $this->moduleName ? "Modules\\{$this->moduleName}\\App\\Http\\Requests\\{$this->modelName}" : "App\\Http\\Requests\\Admin\\{$this->modelName}", + "namespace" => $this->moduleName ? "Modules\\{$this->moduleName}\\Http\\Requests\\{$this->modelName}" : "App\\Http\\Requests\\Admin\\{$this->modelName}", ], [ - $this->moduleName ? module_path($this->moduleName) ."/App/Http/Requests": app_path("Http/Requests/Admin"), - $this->moduleName ? module_path($this->moduleName) ."/App/Http/Requests/{$this->modelName}": app_path("Http/Requests/Admin/{$this->modelName}"), + $this->moduleName ? module_path($this->moduleName) ."/app/Http/Requests": app_path("Http/Requests/Admin"), + $this->moduleName ? module_path($this->moduleName) ."/app/Http/Requests/{$this->modelName}": app_path("Http/Requests/Admin/{$this->modelName}"), ] ); } diff --git a/src/Services/Concerns/GenerateRoutes.php b/src/Services/Concerns/GenerateRoutes.php index f23db2d..fc2792b 100644 --- a/src/Services/Concerns/GenerateRoutes.php +++ b/src/Services/Concerns/GenerateRoutes.php @@ -11,11 +11,11 @@ private function generateRoutes() $this->stubPath . "route.stub", $this->moduleName ? module_path($this->moduleName) . "/routes/web.php" : base_path("routes/web.php"), [ - "name" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Http\\Controllers\\{$this->modelName}Controller" : "App\\Http\\Controllers\\Admin\\{$this->modelName}Controller", + "name" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\Http\\Controllers\\{$this->modelName}Controller" : "App\\Http\\Controllers\\Admin\\{$this->modelName}Controller", "table" => str_replace('_', '-', $this->tableName) ], [ - $this->moduleName ? module_path($this->moduleName) . "/Routes" : base_path("routes") + $this->moduleName ? module_path($this->moduleName) . "/routes" : base_path("routes") ], true ); @@ -26,11 +26,11 @@ private function generateRoutes() $this->stubPath . "api-route.stub", $this->moduleName ? module_path($this->moduleName) . "/routes/api.php" : base_path("routes/api.php"), [ - "name" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Http\\Controllers\\{$this->modelName}Controller" : "App\\Http\\Controllers\\Admin\\{$this->modelName}Controller", + "name" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\Http\\Controllers\\{$this->modelName}Controller" : "App\\Http\\Controllers\\Admin\\{$this->modelName}Controller", "table" => str_replace('_', '-', $this->tableName) ], [ - $this->moduleName ? module_path($this->moduleName) . "/Routes" : base_path("routes") + $this->moduleName ? module_path($this->moduleName) . "/routes" : base_path("routes") ], true ); diff --git a/src/Services/Concerns/GenerateTable.php b/src/Services/Concerns/GenerateTable.php index 5eb9ab2..7d2e720 100644 --- a/src/Services/Concerns/GenerateTable.php +++ b/src/Services/Concerns/GenerateTable.php @@ -11,17 +11,17 @@ private function generateTable(): void { $this->generateStubs( $this->stubPath . "table.stub", - $this->moduleName ? module_path($this->moduleName). "/App/Tables/{$this->modelName}Table.php" : app_path("Tables/{$this->modelName}Table.php"), + $this->moduleName ? module_path($this->moduleName). "/app/Tables/{$this->modelName}Table.php" : app_path("Tables/{$this->modelName}Table.php"), [ "name" => "{$this->modelName}Table", "title" => $this->modelName, - "model" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Models\\".$this->modelName :"\\App\\Models\\".$this->modelName, + "model" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\Models\\".$this->modelName :"\\App\\Models\\".$this->modelName, "searchable" => $this->generateSearchable(), "cols" => $this->generateCols(), - "namespace" => $this->moduleName ? "Modules\\".$this->moduleName."\\App\\Tables" : "App\\Tables", + "namespace" => $this->moduleName ? "Modules\\".$this->moduleName."\\Tables" : "App\\Tables", ], [ - $this->moduleName ? module_path($this->moduleName)."/App/Tables" : app_path("Tables") + $this->moduleName ? module_path($this->moduleName)."/app/Tables" : app_path("Tables") ] ); }