├── .github └── FUNDING.yml ├── .idea ├── .gitignore ├── git_toolbox_prj.xml ├── modules.xml ├── php.xml ├── tomato-php.iml └── vcs.xml ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── SECURITY.md ├── art └── screenshot.png ├── composer.json ├── config └── tomato-php.php ├── src ├── Console │ ├── TomatoGenerator.php │ ├── TomatoGeneratorControllers.php │ ├── TomatoGeneratorForm.php │ ├── TomatoGeneratorMenus.php │ ├── TomatoGeneratorModels.php │ ├── TomatoGeneratorRoutes.php │ ├── TomatoGeneratorTables.php │ └── TomatoGeneratorViews.php ├── Http │ └── Middleware │ │ └── LanguageSwitcher.php ├── Interfaces │ └── TomatoBase.php ├── Services │ └── Generator │ │ ├── CRUDGenerator.php │ │ └── Concerns │ │ ├── GenerateCasts.php │ │ ├── GenerateCols.php │ │ ├── GenerateController.php │ │ ├── GenerateCreateView.php │ │ ├── GenerateEditView.php │ │ ├── GenerateFolders.php │ │ ├── GenerateForm.php │ │ ├── GenerateFormView.php │ │ ├── GenerateIndexView.php │ │ ├── GenerateJsonResource.php │ │ ├── GenerateMenus.php │ │ ├── GenerateModel.php │ │ ├── GenerateRequest.php │ │ ├── GenerateRoutes.php │ │ ├── GenerateRules.php │ │ ├── GenerateShowView.php │ │ ├── GenerateTable.php │ │ └── InjectString.php └── TomatoPHPServiceProvider.php ├── stubs ├── FormBuilder │ ├── BuilderController.stub │ ├── Form.stub │ └── FormClass.stub ├── api-route.stub ├── casts.stub ├── controller-request.stub ├── controller.stub ├── create.stub ├── edit.stub ├── index.stub ├── json.stub ├── menu.stub ├── request.stub ├── route.stub ├── table.stub └── view.stub └── tests └── .gitkeep /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [3x1io] 2 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/git_toolbox_prj.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/php.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 9 | 10 | 12 | 13 | 15 | 16 | 18 | 19 | 21 | -------------------------------------------------------------------------------- /.idea/tomato-php.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/tomato-php/4ecec3677c28c7a7ec8352e7627095ed955233bb/CHANGELOG.md -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Fady Mondy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Screenshot](https://github.com/tomatophp/tomato-php/blob/master/art/screenshot.png) 2 | 3 | # Tomato PHP 4 | 5 | 🍅 Tomato PHP is a Full CRUD Generator for [Splade](https://splade.dev/) & [Breeze Starter Kit](https://splade.dev/docs/breeze) 6 | 7 | ## Installation 8 | 9 | ```bash 10 | composer require tomatophp/tomato-php 11 | ``` 12 | 13 | ## Support 14 | 15 | you can join our discord server to get support [TomatoPHP](https://discord.gg/Xqmt35Uh) 16 | 17 | ## Docs 18 | 19 | you can check docs of this package on [Docs](https://docs.tomatophp.com/tomato-php) 20 | 21 | ## Changelog 22 | 23 | Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. 24 | 25 | ## Credits 26 | 27 | - [Fady Mondy](https://github.com/3x1io) 28 | 29 | ## License 30 | 31 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 32 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/tomato-php/4ecec3677c28c7a7ec8352e7627095ed955233bb/SECURITY.md -------------------------------------------------------------------------------- /art/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/tomato-php/4ecec3677c28c7a7ec8352e7627095ed955233bb/art/screenshot.png -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tomatophp/tomato-php", 3 | "type": "library", 4 | "description": "Full CRUD Generator for Splade & Breeze Starter Kit", 5 | "keywords": [ 6 | "Splade", 7 | "Breeze", 8 | "inertiajs", 9 | "vuejs", 10 | "blade", 11 | "php8", 12 | "laravel" 13 | ], 14 | "license": "MIT", 15 | "autoload": { 16 | "psr-4": { 17 | "TomatoPHP\\TomatoPHP\\": "src/" 18 | } 19 | }, 20 | "autoload-dev": { 21 | "psr-4": { 22 | "Tests\\": "tests/" 23 | } 24 | }, 25 | "extra": { 26 | "laravel": { 27 | "providers": [ 28 | "TomatoPHP\\TomatoPHP\\TomatoPHPServiceProvider" 29 | ] 30 | } 31 | }, 32 | "authors": [ 33 | { 34 | "name": "Fady Mondy", 35 | "email": "EngFadyMondy@gmail.com" 36 | } 37 | ], 38 | "require": { 39 | "php": "^8.1|^8.2", 40 | "tomatophp/tomato-splade": "^1.1", 41 | "tomatophp/tomato-admin": "^1.1", 42 | "tomatophp/console-helpers": "^1.1", 43 | "tomatophp/tomato-model-generator": "^1.0", 44 | "nwidart/laravel-modules": "^10.0", 45 | "laravel/prompts": "^v0.1" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /config/tomato-php.php: -------------------------------------------------------------------------------- 1 | "vendor/tomatophp/tomato-php/stubs", 5 | ]; 6 | -------------------------------------------------------------------------------- /src/Console/TomatoGenerator.php: -------------------------------------------------------------------------------- 1 | getTableListing(); 49 | 50 | $tableName = $this->argument('table') && $this->argument('table') != "0" ? $this->argument('table') : search( 51 | label: 'Please input your table name you went to create CRUD?', 52 | options: fn (string $value) => strlen($value) > 0 53 | ? collect($tables)->filter(function ($item, $key) use ($value){ 54 | return Str::contains($item, $value) ? (string)$item : null; 55 | })->toArray() 56 | : [], 57 | placeholder: "ex: users", 58 | scroll: 10 59 | ); 60 | 61 | if(is_numeric($tableName)){ 62 | $tableName = $tables[$tableName]; 63 | } 64 | else { 65 | $tableName = $tableName; 66 | } 67 | 68 | //Check if user need to use HMVC 69 | $isModule = ($this->argument('module') && $this->argument('module') != "0") ?: confirm('Do you went to use HMVC module?'); 70 | $moduleName = false; 71 | if ($isModule){ 72 | if (class_exists(\Nwidart\Modules\Facades\Module::class)){ 73 | $modules = \Nwidart\Modules\Facades\Module::toCollection()->map(function ($item){ 74 | return $item->getName(); 75 | }); 76 | $moduleName = ($this->argument('module') && $this->argument('module') != "0") ? $this->argument('module') : suggest( 77 | label:'Please input your module name?', 78 | placeholder:'Translations', 79 | options: fn (string $value) => strlen($value) > 0 80 | ? collect($modules)->filter(function ($item, $key) use ($value){ 81 | return Str::contains($item, $value) ? $item : null; 82 | })->toArray() 83 | : [], 84 | validate: fn (string $value) => match (true) { 85 | strlen($value) < 1 => "Sorry this filed is required!", 86 | default => null 87 | }, 88 | scroll: 10 89 | ); 90 | $check = \Nwidart\Modules\Facades\Module::find($moduleName); 91 | if (!$check) { 92 | $createIt = confirm('Module not found! do you when to create it?'); 93 | $createIt ? $this->artisanCommand(["module:make", $moduleName]) : $moduleName = null; 94 | \Laravel\Prompts\info('We Generate It please re-run the command again'); 95 | exit(); 96 | } 97 | } 98 | else { 99 | $installItem = confirm('Sorry nwidart/laravel-modules not installed please install it first. do you when to install it?'); 100 | if($installItem){ 101 | $this->requireComposerPackages(["nwidart/laravel-modules"]); 102 | \Laravel\Prompts\info('Add This line to composer.json psr-4 autoload'); 103 | \Laravel\Prompts\info('"Modules\\" : "Modules/"'); 104 | \Laravel\Prompts\info('now run'); 105 | \Laravel\Prompts\info('composer dump-autoload'); 106 | \Laravel\Prompts\info('Install success please run the command again'); 107 | exit(); 108 | } 109 | } 110 | } 111 | 112 | $generateAPI = ($this->option('api') && $this->option('api') != "0") ? $this->option('api') : confirm( 113 | label: 'Do you went to generate api routes?', 114 | ); 115 | 116 | $generateForm = ($this->option('builder') && $this->option('builder') != "0") ? $this->option('builder') : confirm( 117 | label: 'Do you went to use form class builder?', 118 | ); 119 | 120 | //Generate CRUD Service 121 | try { 122 | \Laravel\Prompts\spin(fn()=> (new CRUDGenerator( 123 | tableName:$tableName, 124 | moduleName:$moduleName, 125 | apiRoutes: $generateAPI, 126 | form: $generateForm, 127 | ))->generate(), 'Generating ...'); 128 | } catch (\Exception $e) { 129 | \Laravel\Prompts\error($e); 130 | } 131 | 132 | \Laravel\Prompts\info('🍅 Thanks for using Tomato Plugins & TomatoPHP framework'); 133 | \Laravel\Prompts\info('💼 Join support server on discord https://discord.gg/VZc8nBJ3ZU'); 134 | \Laravel\Prompts\info('📄 You can check docs here https://docs.tomatophp.com'); 135 | \Laravel\Prompts\info('⭐ please gave us a start on any repo if you like it https://github.com/tomatophp'); 136 | \Laravel\Prompts\info('🤝 sponser us here https://github.com/sponsors/3x1io'); 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/Console/TomatoGeneratorControllers.php: -------------------------------------------------------------------------------- 1 | map(function ($item){ 49 | return $item->{'Tables_in_'.config('database.connections.mysql.database')}; 50 | })->toArray(); 51 | 52 | $tableName = $this->argument('table') && $this->argument('table') != "0" ? $this->argument('table') : search( 53 | label: 'Please input your table name you went to create CRUD?', 54 | options: fn (string $value) => strlen($value) > 0 55 | ? collect($tables)->filter(function ($item, $key) use ($value){ 56 | return Str::contains($item, $value) ? (string)$item : null; 57 | })->toArray() 58 | : [], 59 | placeholder: "ex: users", 60 | scroll: 10 61 | ); 62 | 63 | if(is_numeric($tableName)){ 64 | $tableName = $tables[$tableName]; 65 | } 66 | else { 67 | $tableName = $tableName; 68 | } 69 | 70 | //Check if user need to use HMVC 71 | $isModule = ($this->argument('module') && $this->argument('module') != "0") ?: confirm('Do you went to use HMVC module?'); 72 | $moduleName = false; 73 | if ($isModule){ 74 | if (class_exists(\Nwidart\Modules\Facades\Module::class)){ 75 | $modules = \Nwidart\Modules\Facades\Module::toCollection()->map(function ($item){ 76 | return $item->getName(); 77 | }); 78 | $moduleName = ($this->argument('module') && $this->argument('module') != "0") ? $this->argument('module') : suggest( 79 | label:'Please input your module name?', 80 | placeholder:'Translations', 81 | options: fn (string $value) => strlen($value) > 0 82 | ? collect($modules)->filter(function ($item, $key) use ($value){ 83 | return Str::contains($item, $value) ? $item : null; 84 | })->toArray() 85 | : [], 86 | validate: fn (string $value) => match (true) { 87 | strlen($value) < 1 => "Sorry this filed is required!", 88 | default => null 89 | }, 90 | scroll: 10 91 | ); 92 | $check = \Nwidart\Modules\Facades\Module::find($moduleName); 93 | if (!$check) { 94 | $createIt = confirm('Module not found! do you when to create it?'); 95 | $createIt ? $this->artisanCommand(["module:make", $moduleName]) : $moduleName = null; 96 | \Laravel\Prompts\info('We Generate It please re-run the command again'); 97 | exit(); 98 | } 99 | } 100 | else { 101 | $installItem = confirm('Sorry nwidart/laravel-modules not installed please install it first. do you when to install it?'); 102 | if($installItem){ 103 | $this->requireComposerPackages(["nwidart/laravel-modules"]); 104 | \Laravel\Prompts\info('Add This line to composer.json psr-4 autoload'); 105 | \Laravel\Prompts\info('"Modules\\" : "Modules/"'); 106 | \Laravel\Prompts\info('now run'); 107 | \Laravel\Prompts\info('composer dump-autoload'); 108 | \Laravel\Prompts\info('Install success please run the command again'); 109 | exit(); 110 | } 111 | } 112 | } 113 | 114 | $generateRequest = ($this->option('request') && $this->option('request') != "0") ? $this->option('request') : confirm( 115 | label: 'Do you went to generate form request?', 116 | ); 117 | 118 | $generateResource = ($this->option('resource') && $this->option('resource') != "0") ? $this->option('resource') : confirm( 119 | label: 'Do you went to generate json resource?', 120 | ); 121 | 122 | 123 | //Generate CRUD Service 124 | try { 125 | \Laravel\Prompts\spin(fn()=> (new CRUDGenerator( 126 | tableName:$tableName, 127 | moduleName:$moduleName, 128 | models: false, 129 | views: false, 130 | routes: false, 131 | tables: false, 132 | controllers: true, 133 | request: $generateRequest, 134 | json: $generateResource, 135 | apiRoutes: false, 136 | form: false, 137 | menu: false, 138 | ))->generate(), 'Generating ...'); 139 | } catch (\Exception $e) { 140 | \Laravel\Prompts\error($e); 141 | } 142 | 143 | \Laravel\Prompts\info('🍅 Thanks for using Tomato Plugins & TomatoPHP framework'); 144 | \Laravel\Prompts\info('💼 Join support server on discord https://discord.gg/VZc8nBJ3ZU'); 145 | \Laravel\Prompts\info('📄 You can check docs here https://docs.tomatophp.com'); 146 | \Laravel\Prompts\info('⭐ please gave us a start on any repo if you like it https://github.com/tomatophp'); 147 | \Laravel\Prompts\info('🤝 sponser us here https://github.com/sponsors/3x1io'); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/Console/TomatoGeneratorForm.php: -------------------------------------------------------------------------------- 1 | map(function ($item){ 49 | return $item->{'Tables_in_'.config('database.connections.mysql.database')}; 50 | })->toArray(); 51 | 52 | $tableName = $this->argument('table') && $this->argument('table') != "0" ? $this->argument('table') : search( 53 | label: 'Please input your table name you went to create CRUD?', 54 | options: fn (string $value) => strlen($value) > 0 55 | ? collect($tables)->filter(function ($item, $key) use ($value){ 56 | return Str::contains($item, $value) ? (string)$item : null; 57 | })->toArray() 58 | : [], 59 | placeholder: "ex: users", 60 | scroll: 10 61 | ); 62 | 63 | if(is_numeric($tableName)){ 64 | $tableName = $tables[$tableName]; 65 | } 66 | else { 67 | $tableName = $tableName; 68 | } 69 | 70 | //Check if user need to use HMVC 71 | $isModule = ($this->argument('module') && $this->argument('module') != "0") ?: confirm('Do you went to use HMVC module?'); 72 | $moduleName = false; 73 | if ($isModule){ 74 | if (class_exists(\Nwidart\Modules\Facades\Module::class)){ 75 | $modules = \Nwidart\Modules\Facades\Module::toCollection()->map(function ($item){ 76 | return $item->getName(); 77 | }); 78 | $moduleName = ($this->argument('module') && $this->argument('module') != "0") ? $this->argument('module') : suggest( 79 | label:'Please input your module name?', 80 | placeholder:'Translations', 81 | options: fn (string $value) => strlen($value) > 0 82 | ? collect($modules)->filter(function ($item, $key) use ($value){ 83 | return Str::contains($item, $value) ? $item : null; 84 | })->toArray() 85 | : [], 86 | validate: fn (string $value) => match (true) { 87 | strlen($value) < 1 => "Sorry this filed is required!", 88 | default => null 89 | }, 90 | scroll: 10 91 | ); 92 | $check = \Nwidart\Modules\Facades\Module::find($moduleName); 93 | if (!$check) { 94 | $createIt = confirm('Module not found! do you when to create it?'); 95 | $createIt ? $this->artisanCommand(["module:make", $moduleName]) : $moduleName = null; 96 | \Laravel\Prompts\info('We Generate It please re-run the command again'); 97 | exit(); 98 | } 99 | } 100 | else { 101 | $installItem = confirm('Sorry nwidart/laravel-modules not installed please install it first. do you when to install it?'); 102 | if($installItem){ 103 | $this->requireComposerPackages(["nwidart/laravel-modules"]); 104 | \Laravel\Prompts\info('Add This line to composer.json psr-4 autoload'); 105 | \Laravel\Prompts\info('"Modules\\" : "Modules/"'); 106 | \Laravel\Prompts\info('now run'); 107 | \Laravel\Prompts\info('composer dump-autoload'); 108 | \Laravel\Prompts\info('Install success please run the command again'); 109 | exit(); 110 | } 111 | } 112 | } 113 | 114 | $generateControllers = ($this->option('controller') && $this->option('controller') != "0") ? $this->option('controller') : confirm( 115 | label: 'Do you went to generate controllers for the form?', 116 | ); 117 | 118 | $generateViews = ($this->option('views') && $this->option('views') != "0") ? $this->option('views') : confirm( 119 | label: 'Do you went to generate views for the form?', 120 | ); 121 | 122 | 123 | 124 | //Generate CRUD Service 125 | try { 126 | \Laravel\Prompts\spin(fn()=> (new CRUDGenerator( 127 | tableName:$tableName, 128 | moduleName:$moduleName, 129 | models: false, 130 | views: $generateViews, 131 | routes: false, 132 | tables: false, 133 | controllers: $generateControllers, 134 | request: false, 135 | json: false, 136 | apiRoutes: false, 137 | form: true, 138 | menu: false, 139 | ))->generate(), 'Generating ...'); 140 | } catch (\Exception $e) { 141 | \Laravel\Prompts\error($e); 142 | } 143 | 144 | \Laravel\Prompts\info('🍅 Thanks for using Tomato Plugins & TomatoPHP framework'); 145 | \Laravel\Prompts\info('💼 Join support server on discord https://discord.gg/VZc8nBJ3ZU'); 146 | \Laravel\Prompts\info('📄 You can check docs here https://docs.tomatophp.com'); 147 | \Laravel\Prompts\info('⭐ please gave us a start on any repo if you like it https://github.com/tomatophp'); 148 | \Laravel\Prompts\info('🤝 sponser us here https://github.com/sponsors/3x1io'); 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /src/Console/TomatoGeneratorMenus.php: -------------------------------------------------------------------------------- 1 | map(function ($item){ 47 | return $item->{'Tables_in_'.config('database.connections.mysql.database')}; 48 | })->toArray(); 49 | 50 | $tableName = $this->argument('table') && $this->argument('table') != "0" ? $this->argument('table') : search( 51 | label: 'Please input your table name you went to create CRUD?', 52 | options: fn (string $value) => strlen($value) > 0 53 | ? collect($tables)->filter(function ($item, $key) use ($value){ 54 | return Str::contains($item, $value) ? (string)$item : null; 55 | })->toArray() 56 | : [], 57 | placeholder: "ex: users", 58 | scroll: 10 59 | ); 60 | 61 | if(is_numeric($tableName)){ 62 | $tableName = $tables[$tableName]; 63 | } 64 | else { 65 | $tableName = $tableName; 66 | } 67 | 68 | //Check if user need to use HMVC 69 | $isModule = ($this->argument('module') && $this->argument('module') != "0") ?: confirm('Do you went to use HMVC module?'); 70 | $moduleName = false; 71 | if ($isModule){ 72 | if (class_exists(\Nwidart\Modules\Facades\Module::class)){ 73 | $modules = \Nwidart\Modules\Facades\Module::toCollection()->map(function ($item){ 74 | return $item->getName(); 75 | }); 76 | $moduleName = ($this->argument('module') && $this->argument('module') != "0") ? $this->argument('module') : suggest( 77 | label:'Please input your module name?', 78 | placeholder:'Translations', 79 | options: fn (string $value) => strlen($value) > 0 80 | ? collect($modules)->filter(function ($item, $key) use ($value){ 81 | return Str::contains($item, $value) ? $item : null; 82 | })->toArray() 83 | : [], 84 | validate: fn (string $value) => match (true) { 85 | strlen($value) < 1 => "Sorry this filed is required!", 86 | default => null 87 | }, 88 | scroll: 10 89 | ); 90 | $check = \Nwidart\Modules\Facades\Module::find($moduleName); 91 | if (!$check) { 92 | $createIt = confirm('Module not found! do you when to create it?'); 93 | $createIt ? $this->artisanCommand(["module:make", $moduleName]) : $moduleName = null; 94 | \Laravel\Prompts\info('We Generate It please re-run the command again'); 95 | exit(); 96 | } 97 | } 98 | else { 99 | $installItem = confirm('Sorry nwidart/laravel-modules not installed please install it first. do you when to install it?'); 100 | if($installItem){ 101 | $this->requireComposerPackages(["nwidart/laravel-modules"]); 102 | \Laravel\Prompts\info('Add This line to composer.json psr-4 autoload'); 103 | \Laravel\Prompts\info('"Modules\\" : "Modules/"'); 104 | \Laravel\Prompts\info('now run'); 105 | \Laravel\Prompts\info('composer dump-autoload'); 106 | \Laravel\Prompts\info('Install success please run the command again'); 107 | exit(); 108 | } 109 | } 110 | } 111 | 112 | 113 | //Generate CRUD Service 114 | try { 115 | \Laravel\Prompts\spin(fn()=> (new CRUDGenerator( 116 | tableName:$tableName, 117 | moduleName:$moduleName, 118 | models: false, 119 | views: false, 120 | routes: false, 121 | tables: false, 122 | controllers: false, 123 | request: false, 124 | json: false, 125 | apiRoutes: false, 126 | form: false, 127 | menu: true, 128 | ))->generate(), 'Generating ...'); 129 | } catch (\Exception $e) { 130 | \Laravel\Prompts\error($e); 131 | } 132 | 133 | \Laravel\Prompts\info('🍅 Thanks for using Tomato Plugins & TomatoPHP framework'); 134 | \Laravel\Prompts\info('💼 Join support server on discord https://discord.gg/VZc8nBJ3ZU'); 135 | \Laravel\Prompts\info('📄 You can check docs here https://docs.tomatophp.com'); 136 | \Laravel\Prompts\info('⭐ please gave us a start on any repo if you like it https://github.com/tomatophp'); 137 | \Laravel\Prompts\info('🤝 sponser us here https://github.com/sponsors/3x1io'); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/Console/TomatoGeneratorModels.php: -------------------------------------------------------------------------------- 1 | map(function ($item){ 47 | return $item->{'Tables_in_'.config('database.connections.mysql.database')}; 48 | })->toArray(); 49 | 50 | $tableName = $this->argument('table') && $this->argument('table') != "0" ? $this->argument('table') : search( 51 | label: 'Please input your table name you went to create CRUD?', 52 | options: fn (string $value) => strlen($value) > 0 53 | ? collect($tables)->filter(function ($item, $key) use ($value){ 54 | return Str::contains($item, $value) ? (string)$item : null; 55 | })->toArray() 56 | : [], 57 | placeholder: "ex: users", 58 | scroll: 10 59 | ); 60 | 61 | if(is_numeric($tableName)){ 62 | $tableName = $tables[$tableName]; 63 | } 64 | else { 65 | $tableName = $tableName; 66 | } 67 | 68 | //Check if user need to use HMVC 69 | $isModule = ($this->argument('module') && $this->argument('module') != "0") ?: confirm('Do you went to use HMVC module?'); 70 | $moduleName = false; 71 | if ($isModule){ 72 | if (class_exists(\Nwidart\Modules\Facades\Module::class)){ 73 | $modules = \Nwidart\Modules\Facades\Module::toCollection()->map(function ($item){ 74 | return $item->getName(); 75 | }); 76 | $moduleName = ($this->argument('module') && $this->argument('module') != "0") ? $this->argument('module') : suggest( 77 | label:'Please input your module name?', 78 | placeholder:'Translations', 79 | options: fn (string $value) => strlen($value) > 0 80 | ? collect($modules)->filter(function ($item, $key) use ($value){ 81 | return Str::contains($item, $value) ? $item : null; 82 | })->toArray() 83 | : [], 84 | validate: fn (string $value) => match (true) { 85 | strlen($value) < 1 => "Sorry this filed is required!", 86 | default => null 87 | }, 88 | scroll: 10 89 | ); 90 | $check = \Nwidart\Modules\Facades\Module::find($moduleName); 91 | if (!$check) { 92 | $createIt = confirm('Module not found! do you when to create it?'); 93 | $createIt ? $this->artisanCommand(["module:make", $moduleName]) : $moduleName = null; 94 | \Laravel\Prompts\info('We Generate It please re-run the command again'); 95 | exit(); 96 | } 97 | } 98 | else { 99 | $installItem = confirm('Sorry nwidart/laravel-modules not installed please install it first. do you when to install it?'); 100 | if($installItem){ 101 | $this->requireComposerPackages(["nwidart/laravel-modules"]); 102 | \Laravel\Prompts\info('Add This line to composer.json psr-4 autoload'); 103 | \Laravel\Prompts\info('"Modules\\" : "Modules/"'); 104 | \Laravel\Prompts\info('now run'); 105 | \Laravel\Prompts\info('composer dump-autoload'); 106 | \Laravel\Prompts\info('Install success please run the command again'); 107 | exit(); 108 | } 109 | } 110 | } 111 | 112 | 113 | //Generate CRUD Service 114 | try { 115 | \Laravel\Prompts\spin(fn()=> (new CRUDGenerator( 116 | tableName:$tableName, 117 | moduleName:$moduleName, 118 | models: true, 119 | views: false, 120 | routes: false, 121 | tables: false, 122 | controllers: false, 123 | request: false, 124 | json: false, 125 | apiRoutes: false, 126 | form: false, 127 | menu: false, 128 | ))->generate(), 'Generating ...'); 129 | } catch (\Exception $e) { 130 | \Laravel\Prompts\error($e); 131 | } 132 | 133 | \Laravel\Prompts\info('🍅 Thanks for using Tomato Plugins & TomatoPHP framework'); 134 | \Laravel\Prompts\info('💼 Join support server on discord https://discord.gg/VZc8nBJ3ZU'); 135 | \Laravel\Prompts\info('📄 You can check docs here https://docs.tomatophp.com'); 136 | \Laravel\Prompts\info('⭐ please gave us a start on any repo if you like it https://github.com/tomatophp'); 137 | \Laravel\Prompts\info('🤝 sponser us here https://github.com/sponsors/3x1io'); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/Console/TomatoGeneratorRoutes.php: -------------------------------------------------------------------------------- 1 | map(function ($item){ 48 | return $item->{'Tables_in_'.config('database.connections.mysql.database')}; 49 | })->toArray(); 50 | 51 | $tableName = $this->argument('table') && $this->argument('table') != "0" ? $this->argument('table') : search( 52 | label: 'Please input your table name you went to create CRUD?', 53 | options: fn (string $value) => strlen($value) > 0 54 | ? collect($tables)->filter(function ($item, $key) use ($value){ 55 | return Str::contains($item, $value) ? (string)$item : null; 56 | })->toArray() 57 | : [], 58 | placeholder: "ex: users", 59 | scroll: 10 60 | ); 61 | 62 | if(is_numeric($tableName)){ 63 | $tableName = $tables[$tableName]; 64 | } 65 | else { 66 | $tableName = $tableName; 67 | } 68 | 69 | //Check if user need to use HMVC 70 | $isModule = ($this->argument('module') && $this->argument('module') != "0") ?: confirm('Do you went to use HMVC module?'); 71 | $moduleName = false; 72 | if ($isModule){ 73 | if (class_exists(\Nwidart\Modules\Facades\Module::class)){ 74 | $modules = \Nwidart\Modules\Facades\Module::toCollection()->map(function ($item){ 75 | return $item->getName(); 76 | }); 77 | $moduleName = ($this->argument('module') && $this->argument('module') != "0") ? $this->argument('module') : suggest( 78 | label:'Please input your module name?', 79 | placeholder:'Translations', 80 | options: fn (string $value) => strlen($value) > 0 81 | ? collect($modules)->filter(function ($item, $key) use ($value){ 82 | return Str::contains($item, $value) ? $item : null; 83 | })->toArray() 84 | : [], 85 | validate: fn (string $value) => match (true) { 86 | strlen($value) < 1 => "Sorry this filed is required!", 87 | default => null 88 | }, 89 | scroll: 10 90 | ); 91 | $check = \Nwidart\Modules\Facades\Module::find($moduleName); 92 | if (!$check) { 93 | $createIt = confirm('Module not found! do you when to create it?'); 94 | $createIt ? $this->artisanCommand(["module:make", $moduleName]) : $moduleName = null; 95 | \Laravel\Prompts\info('We Generate It please re-run the command again'); 96 | exit(); 97 | } 98 | } 99 | else { 100 | $installItem = confirm('Sorry nwidart/laravel-modules not installed please install it first. do you when to install it?'); 101 | if($installItem){ 102 | $this->requireComposerPackages(["nwidart/laravel-modules"]); 103 | \Laravel\Prompts\info('Add This line to composer.json psr-4 autoload'); 104 | \Laravel\Prompts\info('"Modules\\" : "Modules/"'); 105 | \Laravel\Prompts\info('now run'); 106 | \Laravel\Prompts\info('composer dump-autoload'); 107 | \Laravel\Prompts\info('Install success please run the command again'); 108 | exit(); 109 | } 110 | } 111 | } 112 | 113 | $generateAPI = ($this->option('api') && $this->option('api') != "0") ? $this->option('api') : confirm( 114 | label: 'Do you went to generate api routes?', 115 | ); 116 | 117 | 118 | //Generate CRUD Service 119 | try { 120 | \Laravel\Prompts\spin(fn()=> (new CRUDGenerator( 121 | tableName:$tableName, 122 | moduleName:$moduleName, 123 | models: false, 124 | views: false, 125 | routes: true, 126 | tables: false, 127 | controllers: false, 128 | request: false, 129 | json: false, 130 | apiRoutes: $generateAPI, 131 | form: false, 132 | menu: false, 133 | ))->generate(), 'Generating ...'); 134 | } catch (\Exception $e) { 135 | \Laravel\Prompts\error($e); 136 | } 137 | 138 | \Laravel\Prompts\info('🍅 Thanks for using Tomato Plugins & TomatoPHP framework'); 139 | \Laravel\Prompts\info('💼 Join support server on discord https://discord.gg/VZc8nBJ3ZU'); 140 | \Laravel\Prompts\info('📄 You can check docs here https://docs.tomatophp.com'); 141 | \Laravel\Prompts\info('⭐ please gave us a start on any repo if you like it https://github.com/tomatophp'); 142 | \Laravel\Prompts\info('🤝 sponser us here https://github.com/sponsors/3x1io'); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/Console/TomatoGeneratorTables.php: -------------------------------------------------------------------------------- 1 | map(function ($item){ 47 | return $item->{'Tables_in_'.config('database.connections.mysql.database')}; 48 | })->toArray(); 49 | 50 | $tableName = $this->argument('table') && $this->argument('table') != "0" ? $this->argument('table') : search( 51 | label: 'Please input your table name you went to create CRUD?', 52 | options: fn (string $value) => strlen($value) > 0 53 | ? collect($tables)->filter(function ($item, $key) use ($value){ 54 | return Str::contains($item, $value) ? (string)$item : null; 55 | })->toArray() 56 | : [], 57 | placeholder: "ex: users", 58 | scroll: 10 59 | ); 60 | 61 | if(is_numeric($tableName)){ 62 | $tableName = $tables[$tableName]; 63 | } 64 | else { 65 | $tableName = $tableName; 66 | } 67 | 68 | //Check if user need to use HMVC 69 | $isModule = ($this->argument('module') && $this->argument('module') != "0") ?: confirm('Do you went to use HMVC module?'); 70 | $moduleName = false; 71 | if ($isModule){ 72 | if (class_exists(\Nwidart\Modules\Facades\Module::class)){ 73 | $modules = \Nwidart\Modules\Facades\Module::toCollection()->map(function ($item){ 74 | return $item->getName(); 75 | }); 76 | $moduleName = ($this->argument('module') && $this->argument('module') != "0") ? $this->argument('module') : suggest( 77 | label:'Please input your module name?', 78 | placeholder:'Translations', 79 | options: fn (string $value) => strlen($value) > 0 80 | ? collect($modules)->filter(function ($item, $key) use ($value){ 81 | return Str::contains($item, $value) ? $item : null; 82 | })->toArray() 83 | : [], 84 | validate: fn (string $value) => match (true) { 85 | strlen($value) < 1 => "Sorry this filed is required!", 86 | default => null 87 | }, 88 | scroll: 10 89 | ); 90 | $check = \Nwidart\Modules\Facades\Module::find($moduleName); 91 | if (!$check) { 92 | $createIt = confirm('Module not found! do you when to create it?'); 93 | $createIt ? $this->artisanCommand(["module:make", $moduleName]) : $moduleName = null; 94 | \Laravel\Prompts\info('We Generate It please re-run the command again'); 95 | exit(); 96 | } 97 | } 98 | else { 99 | $installItem = confirm('Sorry nwidart/laravel-modules not installed please install it first. do you when to install it?'); 100 | if($installItem){ 101 | $this->requireComposerPackages(["nwidart/laravel-modules"]); 102 | \Laravel\Prompts\info('Add This line to composer.json psr-4 autoload'); 103 | \Laravel\Prompts\info('"Modules\\" : "Modules/"'); 104 | \Laravel\Prompts\info('now run'); 105 | \Laravel\Prompts\info('composer dump-autoload'); 106 | \Laravel\Prompts\info('Install success please run the command again'); 107 | exit(); 108 | } 109 | } 110 | } 111 | 112 | 113 | //Generate CRUD Service 114 | try { 115 | \Laravel\Prompts\spin(fn()=> (new CRUDGenerator( 116 | tableName:$tableName, 117 | moduleName:$moduleName, 118 | models: false, 119 | views: false, 120 | routes: false, 121 | tables: true, 122 | controllers: false, 123 | request: false, 124 | json: false, 125 | apiRoutes: false, 126 | form: false, 127 | menu: false, 128 | ))->generate(), 'Generating ...'); 129 | } catch (\Exception $e) { 130 | \Laravel\Prompts\error($e); 131 | } 132 | 133 | \Laravel\Prompts\info('🍅 Thanks for using Tomato Plugins & TomatoPHP framework'); 134 | \Laravel\Prompts\info('💼 Join support server on discord https://discord.gg/VZc8nBJ3ZU'); 135 | \Laravel\Prompts\info('📄 You can check docs here https://docs.tomatophp.com'); 136 | \Laravel\Prompts\info('⭐ please gave us a start on any repo if you like it https://github.com/tomatophp'); 137 | \Laravel\Prompts\info('🤝 sponser us here https://github.com/sponsors/3x1io'); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/Console/TomatoGeneratorViews.php: -------------------------------------------------------------------------------- 1 | map(function ($item){ 48 | return $item->{'Tables_in_'.config('database.connections.mysql.database')}; 49 | })->toArray(); 50 | 51 | $tableName = $this->argument('table') && $this->argument('table') != "0" ? $this->argument('table') : search( 52 | label: 'Please input your table name you went to create CRUD?', 53 | options: fn (string $value) => strlen($value) > 0 54 | ? collect($tables)->filter(function ($item, $key) use ($value){ 55 | return Str::contains($item, $value) ? (string)$item : null; 56 | })->toArray() 57 | : [], 58 | placeholder: "ex: users", 59 | scroll: 10 60 | ); 61 | 62 | if(is_numeric($tableName)){ 63 | $tableName = $tables[$tableName]; 64 | } 65 | else { 66 | $tableName = $tableName; 67 | } 68 | 69 | //Check if user need to use HMVC 70 | $isModule = ($this->argument('module') && $this->argument('module') != "0") ?: confirm('Do you went to use HMVC module?'); 71 | $moduleName = false; 72 | if ($isModule){ 73 | if (class_exists(\Nwidart\Modules\Facades\Module::class)){ 74 | $modules = \Nwidart\Modules\Facades\Module::toCollection()->map(function ($item){ 75 | return $item->getName(); 76 | }); 77 | $moduleName = ($this->argument('module') && $this->argument('module') != "0") ? $this->argument('module') : suggest( 78 | label:'Please input your module name?', 79 | placeholder:'Translations', 80 | options: fn (string $value) => strlen($value) > 0 81 | ? collect($modules)->filter(function ($item, $key) use ($value){ 82 | return Str::contains($item, $value) ? $item : null; 83 | })->toArray() 84 | : [], 85 | validate: fn (string $value) => match (true) { 86 | strlen($value) < 1 => "Sorry this filed is required!", 87 | default => null 88 | }, 89 | scroll: 10 90 | ); 91 | $check = \Nwidart\Modules\Facades\Module::find($moduleName); 92 | if (!$check) { 93 | $createIt = confirm('Module not found! do you when to create it?'); 94 | $createIt ? $this->artisanCommand(["module:make", $moduleName]) : $moduleName = null; 95 | \Laravel\Prompts\info('We Generate It please re-run the command again'); 96 | exit(); 97 | } 98 | } 99 | else { 100 | $installItem = confirm('Sorry nwidart/laravel-modules not installed please install it first. do you when to install it?'); 101 | if($installItem){ 102 | $this->requireComposerPackages(["nwidart/laravel-modules"]); 103 | \Laravel\Prompts\info('Add This line to composer.json psr-4 autoload'); 104 | \Laravel\Prompts\info('"Modules\\" : "Modules/"'); 105 | \Laravel\Prompts\info('now run'); 106 | \Laravel\Prompts\info('composer dump-autoload'); 107 | \Laravel\Prompts\info('Install success please run the command again'); 108 | exit(); 109 | } 110 | } 111 | } 112 | 113 | $generateForm = ($this->option('builder') && $this->option('builder') != "0") ? $this->option('builder') : confirm( 114 | label: 'Do you went to use views for form class builder?', 115 | ); 116 | 117 | 118 | 119 | //Generate CRUD Service 120 | try { 121 | \Laravel\Prompts\spin(fn()=> (new CRUDGenerator( 122 | tableName:$tableName, 123 | moduleName:$moduleName, 124 | models: false, 125 | views: true, 126 | routes: false, 127 | tables: true, 128 | controllers: false, 129 | request: false, 130 | json: false, 131 | apiRoutes: false, 132 | form: $generateForm, 133 | menu: false, 134 | ))->generate(), 'Generating ...'); 135 | } catch (\Exception $e) { 136 | \Laravel\Prompts\error($e); 137 | } 138 | 139 | \Laravel\Prompts\info('🍅 Thanks for using Tomato Plugins & TomatoPHP framework'); 140 | \Laravel\Prompts\info('💼 Join support server on discord https://discord.gg/VZc8nBJ3ZU'); 141 | \Laravel\Prompts\info('📄 You can check docs here https://docs.tomatophp.com'); 142 | \Laravel\Prompts\info('⭐ please gave us a start on any repo if you like it https://github.com/tomatophp'); 143 | \Laravel\Prompts\info('🤝 sponser us here https://github.com/sponsors/3x1io'); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /src/Http/Middleware/LanguageSwitcher.php: -------------------------------------------------------------------------------- 1 | setLocale($lang->id); 16 | } 17 | else { 18 | $_COOKIE['lang'] = json_encode([ 19 | 'id' => config('app.locale'), 20 | 'name' => config('app.locale') === 'en' ? 'English' : 'Arabic' 21 | ]); 22 | } 23 | 24 | return $next($request); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Interfaces/TomatoBase.php: -------------------------------------------------------------------------------- 1 | config('database.connections.mysql.database'), 87 | 'user' => config('database.connections.mysql.username'), 88 | 'password' => config('database.connections.mysql.password'), 89 | 'host' => config('database.connections.mysql.host'), 90 | 'driver' => 'pdo_mysql', 91 | ]; 92 | 93 | $this->connection = DriverManager::getConnection($connectionParams); 94 | $this->modelName = Str::ucfirst(Str::singular(Str::camel($this->tableName))); 95 | $this->stubPath = base_path(config('tomato-php.stubs-path')) . "/"; 96 | $this->cols = $this->getCols(); 97 | } 98 | 99 | /** 100 | * @return void 101 | */ 102 | public function generate(): void 103 | { 104 | $this->generateFolders(); 105 | sleep(3); 106 | if($this->models){ 107 | $this->generateModel(); 108 | $this->generateCasts(); 109 | } 110 | if($this->tables){ 111 | $this->generateTable(); 112 | } 113 | if($this->form){ 114 | $this->generateControllerForBuilder(); 115 | } 116 | else if($this->request){ 117 | $this->generateRequest(); 118 | $this->generateControllerForRequest(); 119 | } 120 | else { 121 | $this->generateController(); 122 | } 123 | 124 | if($this->json){ 125 | $this->generateJsonResource(); 126 | } 127 | if($this->routes || $this->apiRoutes){ 128 | $this->generateRoutes(); 129 | } 130 | if($this->views){ 131 | $this->generateIndexView(); 132 | if ($this->form){ 133 | $this->generateFormView(); 134 | $this->generateFormBuilderClass(); 135 | 136 | }else{ 137 | $this->generateCreateView(); 138 | $this->generateEditView(); 139 | } 140 | $this->generateShowView(); 141 | } 142 | if($this->menu){ 143 | $this->generateMenus(); 144 | } 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /src/Services/Generator/Concerns/GenerateCasts.php: -------------------------------------------------------------------------------- 1 | injectString( 10 | $this->moduleName ? module_path($this->moduleName) ."/App/Models/{$this->modelName}.php" : app_path("Models/{$this->modelName}.php"), 11 | 'protected $fillable =', 12 | $this->stubPath . "casts.stub", 13 | [ 14 | "casts" => $this->getCasts(), 15 | ] 16 | ); 17 | } 18 | 19 | private function getCasts() 20 | { 21 | $casts = []; 22 | foreach ($this->cols as $key=>$column) { 23 | if ($column['type'] == 'boolean') { 24 | $casts[] = ($key!==0?' ':"") .'\''.$column['name'].'\' => \'boolean\''; 25 | } 26 | elseif ($column['type'] == 'json') { 27 | $casts[] = ($key!==0?' ':"") .'\''.$column['name'].'\' => \'json\''; 28 | } 29 | } 30 | return implode(",\n", $casts); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Services/Generator/Concerns/GenerateCols.php: -------------------------------------------------------------------------------- 1 | connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); 14 | $tableSchema = $this->connection->getSchemaManager(); 15 | $columns = $tableSchema->listTableDetails($this->tableName); 16 | 17 | $types=[]; 18 | 19 | foreach ($columns->getColumns() as $column) { 20 | 21 | if (Str::of($column->getName())->endsWith([ 22 | 'created_at', 23 | 'updated_at', 24 | 'deleted_at', 25 | '_token', 26 | ])) { 27 | continue; 28 | } 29 | 30 | $componentData = []; 31 | 32 | $componentData['name'] = $column->getName(); 33 | $componentData['type']=$column->getType()->getName(); 34 | $componentData['default']=$column->getDefault(); 35 | 36 | 37 | $uniqueName = $this->tableName . '_' . $column->getName() . '_unique'; 38 | if ($columns->hasIndex($uniqueName)) { 39 | $componentData['unique'] = true; 40 | } else { 41 | $componentData['unique'] = false; 42 | } 43 | 44 | if ($componentData['type'] === "string") { 45 | 46 | if (Str::of($column->getName())->contains(['email'])) { 47 | $componentData['type'] = "email"; 48 | } 49 | 50 | if (Str::of($column->getName())->contains(['password'])) { 51 | $componentData['type'] = "password"; 52 | } 53 | 54 | if (Str::of($column->getName())->contains(['phone', 'tel'])) { 55 | $componentData['type'] = "tel"; 56 | } 57 | 58 | if (Str::of($column->getName())->contains(['color'])) { 59 | $componentData['type'] = "color"; 60 | } 61 | 62 | if (Str::of($column->getName())->contains(['icon'])) { 63 | $componentData['type'] = "icon"; 64 | } 65 | } 66 | if ($componentData['type'] === "integer" || $componentData['type'] === "float" || $componentData['type'] === "double") { 67 | $componentData['type'] = "int"; 68 | } 69 | 70 | if (Str::of($column->getName())->endsWith([ 71 | '_id' 72 | ])) 73 | { 74 | 75 | if ($columns->hasForeignKey($this->tableName . '_' . $column->getName() . '_foreign')) { 76 | $getKey = $columns->getForeignKey($this->tableName . '_' . $column->getName() . '_foreign'); 77 | $model = "\\Modules\\" . $this->moduleName . "\\Entities\\" . Str::studly(Str::singular($getKey->getForeignTableName())); 78 | $componentData['relation'] = [ 79 | "table" => $getKey->getForeignTableName(), 80 | "field" => $getKey->getForeignColumns()[0], 81 | "model" => $model, 82 | 'relationColumn'=>'id', 83 | 'relationColumnType'=>'text' 84 | ]; 85 | 86 | $relationTableColumns=\Illuminate\Support\Facades\Schema::getColumnListing($componentData['relation']['table']); 87 | if (array_search('name',$relationTableColumns)) 88 | $componentData['relation']['relationColumn']='name'; 89 | elseif (array_search('title',$relationTableColumns)) 90 | $componentData['relation']['relationColumn']='title'; 91 | 92 | try { 93 | $componentData['relation']['relationColumnType']=\Illuminate\Support\Facades\Schema::getColumnType($componentData['relation']['table'],$componentData['relation']['relationColumn']); 94 | }catch (\Exception $e) {} 95 | 96 | $componentData['type'] = 'relation'; 97 | } 98 | } 99 | 100 | if ($column->getNotnull()) { 101 | $componentData['required'] = 'required'; 102 | } else { 103 | $componentData['required'] = 'nullable'; 104 | } 105 | 106 | 107 | if ($length = $column->getLength()) { 108 | if ($length > 255) { 109 | $componentData['type'] = 'textarea'; 110 | } 111 | $componentData['maxLength'] = $length; 112 | } else { 113 | $componentData['maxLength'] = false; 114 | } 115 | 116 | if($column->getLength() < 1 && $componentData['type'] === 'text'){ 117 | $componentData['type'] = 'longText'; 118 | } 119 | 120 | $components[] = $componentData; 121 | } 122 | 123 | // dd($components); 124 | return $components; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/Services/Generator/Concerns/GenerateController.php: -------------------------------------------------------------------------------- 1 | moduleName ? module_path($this->moduleName) ."/App/Http/Controllers/{$this->modelName}Controller.php" : app_path("Http/Controllers/Admin/{$this->modelName}Controller.php"); 13 | if($isForce){ 14 | if(File::exists($filePath)){ 15 | File::delete($filePath); 16 | } 17 | } 18 | $this->generateStubs( 19 | $this->stubPath . "controller.stub", 20 | $this->moduleName ? module_path($this->moduleName) ."/App/Http/Controllers/{$this->modelName}Controller.php" : app_path("Http/Controllers/Admin/{$this->modelName}Controller.php"), 21 | [ 22 | "name" => "{$this->modelName}Controller", 23 | "model" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Models\\".$this->modelName : "\\App\\Models\\".$this->modelName, 24 | "title" => $this->modelName, 25 | "table" => str_replace('_', '-', $this->tableName), 26 | "validation" => $this->generateRules(), 27 | "validationEdit" => $this->generateRules(true), 28 | "requestNamespace" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Http\\Requests\\{$this->modelName}\\" : "\\App\\Http\\Requests\\Admin\\{$this->modelName}\\", 29 | "tableClass" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Tables\\".$this->modelName."Table" : "\\App\\Tables\\".$this->modelName."Table", 30 | "namespace" => $this->moduleName ? "Modules\\".$this->moduleName."\\App\\Http\\Controllers": "App\\Http\\Controllers\\Admin", 31 | "modulePath" => $this->moduleName ? Str::replace('_', '-', Str::lower($this->moduleName))."::" : "admin." 32 | ], 33 | [ 34 | $this->moduleName ? module_path($this->moduleName) ."/App/Http/Controllers/" : app_path("Http/Controllers/Admin") 35 | ] 36 | ); 37 | } 38 | 39 | private function generateControllerForRequest() 40 | { 41 | $this->generateStubs( 42 | $this->stubPath . "controller-request.stub", 43 | $this->moduleName ? module_path($this->moduleName) ."/App/Http/Controllers/{$this->modelName}Controller.php" : app_path("Http/Controllers/Admin/{$this->modelName}Controller.php"), 44 | [ 45 | "name" => "{$this->modelName}Controller", 46 | "model" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Models\\".$this->modelName : "\\App\\Models\\".$this->modelName, 47 | "title" => $this->modelName, 48 | "table" => str_replace('_', '-', $this->tableName), 49 | "requestNamespace" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Http\\Requests\\{$this->modelName}\\" : "\\App\\Http\\Requests\\Admin\\{$this->modelName}\\", 50 | "tableClass" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Tables\\".$this->modelName."Table" : "\\App\\Tables\\".$this->modelName."Table", 51 | "namespace" => $this->moduleName ? "Modules\\".$this->moduleName."\\App\\Http\\Controllers": "App\\Http\\Controllers\\Admin", 52 | "modulePath" => $this->moduleName ? Str::replace('_', '-', Str::lower($this->moduleName))."::" : "admin." 53 | ], 54 | [ 55 | $this->moduleName ? module_path($this->moduleName) ."/App/Http/Controllers/" : app_path("Http/Controllers/Admin") 56 | ] 57 | ); 58 | } 59 | 60 | private function generateControllerForBuilder() 61 | { 62 | $this->generateStubs( 63 | $this->stubPath ."FormBuilder/BuilderController.stub", 64 | $this->moduleName ? module_path($this->moduleName) ."/App/Http/Controllers/{$this->modelName}Controller.php" : app_path("Http/Controllers/Admin/{$this->modelName}Controller.php"), 65 | [ 66 | "name" => "{$this->modelName}Controller", 67 | "model" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Models\\".$this->modelName : "\\App\\Models\\".$this->modelName, 68 | "title" => $this->modelName, 69 | "table" => str_replace('_', '-', $this->tableName), 70 | "validation" => $this->generateRules(), 71 | "validationEdit" => $this->generateRules(true), 72 | "formClass" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Forms\\{$this->modelName}Form" : "\\App\\Forms\\{$this->modelName}Form", 73 | "requestNamespace" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Http\\Requests\\{$this->modelName}\\" : "\\App\\Http\\Requests\\Admin\\{$this->modelName}\\", 74 | "FormNamespace" => $this->moduleName ? "Modules\\".$this->moduleName."\\App\\Forms\\{$this->modelName}Form" : "App\\Forms\\{$this->modelName}Form", 75 | "tableClass" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Tables\\".$this->modelName."Table" : "\\App\\Tables\\".$this->modelName."Table", 76 | "namespace" => $this->moduleName ? "Modules\\".$this->moduleName."\\App\\Http\\Controllers": "App\\Http\\Controllers\\Admin", 77 | "modulePath" => $this->moduleName ? Str::replace('_', '-', Str::lower($this->moduleName))."::" : "admin." 78 | ], 79 | [ 80 | $this->moduleName ? module_path($this->moduleName) ."/App/Http/Controllers/" : app_path("Http/Controllers/Admin") 81 | ] 82 | ); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Services/Generator/Concerns/GenerateCreateView.php: -------------------------------------------------------------------------------- 1 | moduleName){ 13 | $folders[] = module_path($this->moduleName) . "/resources/views/" . Str::replace('_', '-',$this->tableName); 14 | } 15 | else { 16 | $folders[] = resource_path("views/admin"); 17 | $folders[] = resource_path("views/admin/" . Str::replace('_', '-',$this->tableName)); 18 | } 19 | 20 | $this->generateStubs( 21 | $this->stubPath . "create.stub", 22 | $this->moduleName ? module_path($this->moduleName) . "/resources/views/".str_replace('_', '-', $this->tableName)."/create.blade.php" : resource_path("views/admin/".Str::replace('_', '-',$this->tableName)."/create.blade.php"), 23 | [ 24 | "title" => $this->modelName, 25 | "table" => str_replace('_', '-', $this->tableName), 26 | "cols" => $this->generateForm() 27 | ], 28 | $folders 29 | ); 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Services/Generator/Concerns/GenerateEditView.php: -------------------------------------------------------------------------------- 1 | moduleName){ 13 | $folders[] = module_path($this->moduleName) . "/resources/views/" . Str::replace('_', '-',$this->tableName); 14 | } 15 | else { 16 | $folders[] = resource_path("views/admin"); 17 | $folders[] = resource_path("views/admin/" . Str::replace('_', '-',$this->tableName)); 18 | } 19 | 20 | $this->generateStubs( 21 | $this->stubPath . "edit.stub", 22 | $this->moduleName ? module_path($this->moduleName) . "/resources/views/".str_replace('_', '-', $this->tableName)."/edit.blade.php" : resource_path("views/admin/".Str::replace('_', '-',$this->tableName)."/edit.blade.php"), 23 | [ 24 | "title" => $this->modelName, 25 | "table" => str_replace('_', '-', $this->tableName), 26 | "cols" => $this->generateForm() 27 | ], 28 | $folders 29 | ); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Services/Generator/Concerns/GenerateFolders.php: -------------------------------------------------------------------------------- 1 | moduleName){ 13 | $folders = [ 14 | module_path($this->moduleName) ."/App/Http/Controllers/", 15 | module_path($this->moduleName) ."/App/resources/", 16 | module_path($this->moduleName) ."/App/Http/Requests/", 17 | module_path($this->moduleName) ."/App/Http/Requests/{$this->modelName}", 18 | module_path($this->moduleName) ."/App/Models/", 19 | module_path($this->moduleName) . "/resources/views/" . str_replace('_', '-', $this->tableName), 20 | module_path($this->moduleName) . "/routes", 21 | module_path($this->moduleName)."/App/Tables", 22 | module_path($this->moduleName)."/App/Forms", 23 | ]; 24 | } 25 | else { 26 | $folders = [ 27 | app_path("Http/Controllers") . "/Admin", 28 | app_path("Http/Resources"), 29 | app_path("Http/Requests"), 30 | app_path("Http/Requests/Admin"), 31 | app_path("Http/Requests/Admin/{$this->modelName}"), 32 | app_path("Http/Resources") . "/Admin", 33 | resource_path("views") . '/admin', 34 | resource_path("views") . '/admin/' . str_replace('_', '-', $this->tableName), 35 | base_path("routes"), 36 | app_path("Tables") 37 | ]; 38 | } 39 | 40 | foreach($folders as $folder){ 41 | if(!File::exists($folder)){ 42 | File::makeDirectory($folder); 43 | File::put($folder . "/.gitkeep", ""); 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Services/Generator/Concerns/GenerateForm.php: -------------------------------------------------------------------------------- 1 | '.$text.'" type="'.$type.'" />'.PHP_EOL; 21 | return $form; 22 | } 23 | 24 | private function generateForm(bool $view=false): string 25 | { 26 | $form = ""; 27 | foreach($this->cols as $key=>$item){ 28 | if($key!== 0){ 29 | $form .= " "; 30 | } 31 | if( 32 | $item['type'] === 'string' || 33 | $item['type'] === 'email' || 34 | ($item['name'] === 'password' && !$view) 35 | ){ 36 | $type = $item['type'] === 'string' ? 'text' : $item['type']; 37 | if($view){ 38 | $form .= $this->generateViewItem($item['name'],null, $item['type']); 39 | } 40 | else { 41 | $form .= ""; 42 | if($item['name'] === 'password'){ 43 | $form .= PHP_EOL." "; 44 | } 45 | } 46 | } 47 | if($item['type'] === 'textarea'){ 48 | if($view){ 49 | $form .= $this->generateViewItem($item['name']); 50 | } 51 | else { 52 | $form .= ""; 53 | } 54 | } 55 | if($item['type'] === 'longText'){ 56 | if($view){ 57 | $form .= $this->generateViewItem($item['name'], null, "rich"); 58 | } 59 | else { 60 | $form .= ""; 61 | } 62 | } 63 | if($item['type'] === 'int'){ 64 | if($view){ 65 | $form .= $this->generateViewItem($item['name'], null, "number"); 66 | } 67 | else { 68 | $form .= ""; 69 | } 70 | } 71 | if($item['type'] === 'color'){ 72 | if($view){ 73 | $form .= $this->generateViewItem($item['name'], null, "color"); 74 | } 75 | else { 76 | $form .= ""; 77 | } 78 | } 79 | if($item['type'] === 'icon'){ 80 | if($view){ 81 | $form .= $this->generateViewItem($item['name'], null, "icon"); 82 | } 83 | else { 84 | $form .= ""; 85 | } 86 | } 87 | if($item['type'] === 'relation'){ 88 | if($view){ 89 | 90 | $form .= $this->generateViewItem(Str::remove('_id',$item['name']),Str::remove('_id',Str::ucfirst($item['name']))."->".$item['relation']['relationColumn']); 91 | } 92 | else { 93 | $itemLable=($item['relation']['relationColumnType'] == 'json')?'name.'.app()->getLocale():'name'; 94 | $form .= ""; 95 | } 96 | } 97 | if($item['type'] === 'date'){ 98 | if($view){ 99 | $form .= $this->generateViewItem($item['name']); 100 | } 101 | else { 102 | $form .= ""; 103 | } 104 | } 105 | if($item['type'] === 'time'){ 106 | if($view){ 107 | $form .= $this->generateViewItem($item['name']); 108 | } 109 | else { 110 | $form .= ""; 111 | } 112 | } 113 | if($item['type'] === 'datetime'){ 114 | if($view){ 115 | $form .= $this->generateViewItem($item['name']); 116 | } 117 | else { 118 | $form .= ""; 119 | } 120 | } 121 | if($item['type'] === 'boolean'){ 122 | if($view){ 123 | $form .= $this->generateViewItem($item['name'], null, "bool"); 124 | } 125 | else { 126 | $form .= ""; 127 | } 128 | } 129 | if($item['type'] === 'json' && ($item['name']== 'name' ||$item['name']== 'title'|| $item['name']== 'description')){ 130 | if($view){ 131 | $form .= $this->generateViewItem($item['name']); 132 | } 133 | else { 134 | $form .= ""; 135 | 136 | } 137 | } 138 | 139 | 140 | if($key!== count($this->cols)-1){ 141 | $form .= PHP_EOL; 142 | } 143 | } 144 | return $form; 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /src/Services/Generator/Concerns/GenerateFormView.php: -------------------------------------------------------------------------------- 1 | moduleName) { 14 | $folders[] = module_path($this->moduleName) . "/resources/views/" . Str::replace('_', '-',$this->tableName); 15 | } else { 16 | $folders[] = resource_path("views/admin"); 17 | $folders[] = resource_path("views/admin/" . Str::replace('_', '-',$this->tableName)); 18 | } 19 | 20 | $this->generateStubs( 21 | $this->stubPath ."FormBuilder/Form.stub", 22 | $this->moduleName ? module_path($this->moduleName) . "/resources/views/" . str_replace('_', '-', $this->tableName) . "/form.blade.php" : resource_path("views/admin/".Str::replace('_', '-',$this->tableName)."/form.blade.php"), 23 | [ 24 | "title" => $this->modelName, 25 | "table" => str_replace('_', '-', $this->tableName), 26 | "cols" => $this->generateForm() 27 | ], 28 | $folders 29 | ); 30 | } 31 | 32 | private function generateFormBuilderClass() 33 | { 34 | $this->generateStubs( 35 | $this->stubPath ."FormBuilder/FormClass.stub", 36 | $this->moduleName ? module_path($this->moduleName) . "/App/Forms/{$this->modelName}Form.php" : app_path("Forms/{$this->modelName}Form.php"), 37 | [ 38 | "name" => "{$this->modelName}Form", 39 | "route" => str_replace('_', '-', $this->tableName), 40 | "cols" => $this->generateFormElements(), 41 | "namespace" => $this->moduleName ? "Modules\\" . $this->moduleName . "\\App\\Forms" : "App\\Forms", 42 | ], 43 | [ 44 | $this->moduleName ? module_path($this->moduleName) . "/App/Forms" : app_path("Forms") 45 | ] 46 | ); 47 | } 48 | 49 | private function generateFormElements(): string 50 | { 51 | // $item['type'] === 'tel' || color 52 | $types = ["string" => "Text", "email" => "Email", "tel" => "Text", "password" => "Password", "textarea" => "Textarea", "int" => "Number", "date" => "Date", "datetime" => "Datetime", "time" => "Time"]; 53 | $form = ""; 54 | foreach ($this->cols as $key => $item) { 55 | 56 | if (array_key_exists($item['type'],$types)){ 57 | $form .= " \ProtoneMedia\Splade\FormBuilder\\".$types[$item['type']]."::make('" . $item['name'] . "')->label(__('" . Str::ucfirst(str_replace('_', ' ', $item['name'])) . "')),"; 58 | $form .= PHP_EOL; 59 | } 60 | 61 | if ($item['type']== 'boolean'){ 62 | $form .= " \ProtoneMedia\Splade\FormBuilder\Checkbox::make('" . $item['name'] . "')->label(__('" . Str::ucfirst(str_replace('_', ' ', $item['name'])) . "'))->value(1),"; 63 | $form .= PHP_EOL; 64 | } 65 | 66 | if ($item['type'] === 'relation') { 67 | 68 | $itemLable = ($item['relation']['relationColumnType'] == 'json') ? 'name.' . app()->getLocale() : 'name'; 69 | $form .= " \ProtoneMedia\Splade\FormBuilder\Select::make('".$item['name']."') 70 | ->label(__('".Str::remove('_id',$item['name'])."')) 71 | ->choices() 72 | ->remoteUrl('/admin/".$item['relation']['table']."/api') 73 | ->remoteRoute('model.data') 74 | ->optionLabel('".$itemLable."') 75 | ->optionValue('id'),"; 76 | $form .= PHP_EOL; 77 | } 78 | 79 | if ($item['type'] === 'json' && ($item['name'] == 'name' || $item['name'] == 'title' || $item['name'] == 'description')) { 80 | 81 | $form .= " \ProtoneMedia\Splade\FormBuilder\Text::make('" . $item['name'] . ".ar')->label(__('" . Str::ucfirst(str_replace('_', ' ', $item['name'])) . "_ar')),"; 82 | $form .= PHP_EOL; 83 | $form .= " \ProtoneMedia\Splade\FormBuilder\Text::make('" . $item['name'] . ".en')->label(__('" . Str::ucfirst(str_replace('_', ' ', $item['name'])) . "_en')),"; 84 | $form .= PHP_EOL; 85 | } 86 | 87 | 88 | if ($key !== count($this->cols) - 1) { 89 | $form .= PHP_EOL; 90 | } 91 | } 92 | return $form; 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/Services/Generator/Concerns/GenerateIndexView.php: -------------------------------------------------------------------------------- 1 | moduleName){ 13 | $folders[] = module_path($this->moduleName) . "/resources/views/" . Str::replace('_', '-',$this->tableName); 14 | } 15 | else { 16 | $folders[] = resource_path("views/admin"); 17 | $folders[] = resource_path("views/admin/" . Str::replace('_', '-',$this->tableName)); 18 | } 19 | $this->generateStubs( 20 | $this->stubPath . "index.stub", 21 | $this->moduleName ? module_path($this->moduleName) . "/resources/views/".str_replace('_', '-', $this->tableName)."/index.blade.php" : resource_path("views/admin/".Str::replace('_', '-',$this->tableName)."/index.blade.php"), 22 | [ 23 | "cells" => $this->getCells(), 24 | "title" => $this->modelName, 25 | "table" => str_replace('_', '-', $this->tableName), 26 | "modelClass" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Models\\".$this->modelName : "\\App\\Models\\".$this->modelName, 27 | ], 28 | $folders 29 | ); 30 | } 31 | 32 | /** 33 | * @return string 34 | */ 35 | private function getCells(): string 36 | { 37 | $cell = ""; 38 | foreach ($this->cols as $field){ 39 | if($field['type'] == 'longText'){ 40 | $cell .= ''.PHP_EOL; 41 | $cell .= ' '.PHP_EOL; 42 | $cell .= ''.PHP_EOL; 43 | } 44 | if($field['type'] == 'boolean'){ 45 | $cell .= ''.PHP_EOL; 46 | $cell .= ' '.PHP_EOL; 47 | $cell .= ''.PHP_EOL; 48 | } 49 | if($field['type'] == 'email'){ 50 | $cell .= ''.PHP_EOL; 51 | $cell .= ' '.PHP_EOL; 52 | $cell .= ''.PHP_EOL; 53 | } 54 | if($field['type'] == 'tel'){ 55 | $cell .= ''.PHP_EOL; 56 | $cell .= ' '.PHP_EOL; 57 | $cell .= ''.PHP_EOL; 58 | } 59 | if($field['type'] == 'int'){ 60 | $cell .= ''.PHP_EOL; 61 | $cell .= ' '.PHP_EOL; 62 | $cell .= ''.PHP_EOL; 63 | } 64 | if($field['name'] == 'color'){ 65 | $cell .= ''.PHP_EOL; 66 | $cell .= ' '.PHP_EOL; 67 | $cell .= ''.PHP_EOL; 68 | } 69 | if($field['name'] == 'icon'){ 70 | $cell .= ''.PHP_EOL; 71 | $cell .= ' '.PHP_EOL; 72 | $cell .= ''.PHP_EOL; 73 | } 74 | } 75 | return $cell; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Services/Generator/Concerns/GenerateJsonResource.php: -------------------------------------------------------------------------------- 1 | tableName)->replace('_', ' ')->camel()->ucfirst()->toString() . 'Resource'; 14 | if($this->moduleName){ 15 | $folders[] = module_path($this->moduleName) . "/App/resources"; 16 | } 17 | else { 18 | $folders[] = app_path("Http/Resources"); 19 | } 20 | 21 | $this->generateStubs( 22 | $this->stubPath . "json.stub", 23 | $this->moduleName ? module_path($this->moduleName) . "/App/resources/" . $resourceName . '.php' : app_path("Http/Resources/" . $resourceName . '.php'), 24 | [ 25 | "namespace" => $this->moduleName ? "Modules\\".$this->moduleName."\\App\\resources" : "App\\Http\\Resources", 26 | "name" => $resourceName, 27 | "fields" => $this->generateFields(), 28 | "table" => str_replace('_', '-', $this->tableName), 29 | ], 30 | $folders 31 | ); 32 | 33 | } 34 | 35 | private function generateFields(): string 36 | { 37 | $rules = ""; 38 | foreach ($this->cols as $key => $item) { 39 | if ($item['name'] !== 'id') { 40 | if($key !== 0){ 41 | $rules .= " "; 42 | } 43 | 44 | if($item['name'] === 'relation'){ 45 | $rules .= "'".Str::of($item->name)->remove('_id')->toString()."' => \$this->". $item['relation']['relationColumn'] . ','; 46 | } 47 | else { 48 | $rules .= "'{$item['name']}' => \$this->{$item['name']},"; 49 | } 50 | } 51 | 52 | $rules .= "\n"; 53 | } 54 | 55 | return $rules; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Services/Generator/Concerns/GenerateMenus.php: -------------------------------------------------------------------------------- 1 | injectString( 10 | $this->moduleName ? module_path($this->moduleName) ."/App/Providers/{$this->moduleName}ServiceProvider.php" : app_path("Providers/AppServiceProvider.php"), 11 | $this->moduleName ? '$this->loadMigrationsFrom(module_path($this->moduleName, \'Database/migrations\'));' : 'public function boot(): void', 12 | $this->stubPath . "menu.stub", 13 | [ 14 | "moduleName" =>$this->moduleName ? $this->moduleName : 'App', 15 | "title" => $this->modelName, 16 | "tableName" => str_replace('_', '-', $this->tableName) 17 | ], 18 | $this->moduleName ? 1 : 2 19 | ); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Services/Generator/Concerns/GenerateModel.php: -------------------------------------------------------------------------------- 1 | moduleName){ 14 | if(!file_exists(module_path($this->moduleName) . '/App/Models/'. $this->modelName . '.php')){ 15 | $command = 'krlove:generate:model ' . $this->modelName . ' --table-name=' . $this->tableName . ' --output-path=' . module_path($this->moduleName) . '/App/Models' . ' --namespace=' . "Modules" . "\\\\" . $this->moduleName . "\\\\" . "App" . "\\\\" ."Models"; 16 | } 17 | } 18 | else if(!file_exists(app_path("Models/{$this->modelName}.php"))){ 19 | if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { 20 | // If the platform is Windows 21 | $outputPath = 'Models'; 22 | } else { 23 | // For other platforms 24 | $outputPath = app_path('/Models'); 25 | } 26 | 27 | $command = 'krlove:generate:model ' . $this->modelName . ' --table-name=' . $this->tableName . ' --output-path=' . $outputPath . ' --namespace=' . "\\App\\Models\\"; 28 | } 29 | 30 | if(isset($command)) 31 | Artisan::call($command); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Services/Generator/Concerns/GenerateRequest.php: -------------------------------------------------------------------------------- 1 | generateStubs( 14 | $this->stubPath . "request.stub", 15 | $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"), 16 | [ 17 | "name" => "{$this->modelName}StoreRequest", 18 | "model" => $this->modelName, 19 | "validation" => $this->generateRules(), 20 | "namespace" => $this->moduleName ? "Modules\\{$this->moduleName}\\App\\Http\\Requests\\{$this->modelName}" : "App\\Http\\Requests\\Admin\\{$this->modelName}", 21 | ], 22 | [ 23 | $this->moduleName ? module_path($this->moduleName) ."/App/Http/Requests": app_path("Http/Requests/Admin"), 24 | $this->moduleName ? module_path($this->moduleName) ."/App/Http/Requests/{$this->modelName}": app_path("Http/Requests/Admin/{$this->modelName}"), 25 | ] 26 | ); 27 | 28 | $this->generateStubs( 29 | $this->stubPath . "request.stub", 30 | $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"), 31 | [ 32 | "name" => "{$this->modelName}UpdateRequest", 33 | "model" => $this->modelName, 34 | "validation" => $this->generateRules(true), 35 | "namespace" => $this->moduleName ? "Modules\\{$this->moduleName}\\App\\Http\\Requests\\{$this->modelName}" : "App\\Http\\Requests\\Admin\\{$this->modelName}", 36 | ], 37 | [ 38 | $this->moduleName ? module_path($this->moduleName) ."/App/Http/Requests": app_path("Http/Requests/Admin"), 39 | $this->moduleName ? module_path($this->moduleName) ."/App/Http/Requests/{$this->modelName}": app_path("Http/Requests/Admin/{$this->modelName}"), 40 | ] 41 | ); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Services/Generator/Concerns/GenerateRoutes.php: -------------------------------------------------------------------------------- 1 | routes){ 10 | $this->generateStubs( 11 | $this->stubPath . "route.stub", 12 | $this->moduleName ? module_path($this->moduleName) . "/routes/web.php" : base_path("routes/web.php"), 13 | [ 14 | "name" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Http\\Controllers\\{$this->modelName}Controller" : "App\\Http\\Controllers\\Admin\\{$this->modelName}Controller", 15 | "table" => str_replace('_', '-', $this->tableName) 16 | ], 17 | [ 18 | $this->moduleName ? module_path($this->moduleName) . "/Routes" : base_path("routes") 19 | ], 20 | true 21 | ); 22 | } 23 | 24 | if($this->apiRoutes){ 25 | $this->generateStubs( 26 | $this->stubPath . "api-route.stub", 27 | $this->moduleName ? module_path($this->moduleName) . "/routes/api.php" : base_path("routes/api.php"), 28 | [ 29 | "name" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Http\\Controllers\\{$this->modelName}Controller" : "App\\Http\\Controllers\\Admin\\{$this->modelName}Controller", 30 | "table" => str_replace('_', '-', $this->tableName) 31 | ], 32 | [ 33 | $this->moduleName ? module_path($this->moduleName) . "/Routes" : base_path("routes") 34 | ], 35 | true 36 | ); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Services/Generator/Concerns/GenerateRules.php: -------------------------------------------------------------------------------- 1 | cols as $key => $item) { 11 | if ($item['name'] !== 'id') { 12 | if($key !== 0){ 13 | $rules .= " "; 14 | } 15 | $rules .= "'{$item['name']}' => "; 16 | $rules .= "'"; 17 | if($item['required'] === 'required'){ 18 | if($edit){ 19 | $rules .= 'sometimes'; 20 | } 21 | else { 22 | $rules .= 'required'; 23 | } 24 | 25 | } 26 | else { 27 | $rules .= 'nullable'; 28 | } 29 | 30 | if($item['maxLength']){ 31 | $rules .= '|max:'.$item['maxLength']; 32 | } 33 | if($item['type'] === 'string' || $item['type'] === 'email' || $item['type'] === 'phone'){ 34 | $rules .= '|string'; 35 | } 36 | if($item['type'] === 'email'){ 37 | $rules .= '|email'; 38 | } 39 | if($item['type'] === 'tel'){ 40 | $rules .= '|min:12'; 41 | } 42 | if($item['type'] === 'password'){ 43 | $rules .= '|confirmed|min:6'; 44 | } 45 | if($item['type'] === 'relation'){ 46 | $rules .= '|exists:'.$item['relation']['table'].',id'; 47 | } 48 | 49 | $rules .= "'"; 50 | if (($key !== count($this->cols) - 1)) { 51 | $rules .= ",".PHP_EOL; 52 | } 53 | } 54 | } 55 | 56 | return $rules; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Services/Generator/Concerns/GenerateShowView.php: -------------------------------------------------------------------------------- 1 | moduleName){ 13 | $folders[] = module_path($this->moduleName) . "/resources/views/". Str::replace('_', '-',$this->tableName); 14 | } 15 | else { 16 | $folders[] = resource_path("views/admin"); 17 | $folders[] = resource_path("views/admin/" . Str::replace('_', '-',$this->tableName)); 18 | } 19 | 20 | $this->generateStubs( 21 | $this->stubPath . "view.stub", 22 | $this->moduleName ? module_path($this->moduleName) . "/resources/views/".str_replace('_', '-', $this->tableName)."/show.blade.php" : resource_path("views/admin/".Str::replace('_', '-',$this->tableName)."/show.blade.php"), 23 | [ 24 | "title" => $this->modelName, 25 | "table" => str_replace('_', '-', $this->tableName), 26 | "cols" => $this->generateForm(true) 27 | ], 28 | $folders 29 | ); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Services/Generator/Concerns/GenerateTable.php: -------------------------------------------------------------------------------- 1 | generateStubs( 12 | $this->stubPath . "table.stub", 13 | $this->moduleName ? module_path($this->moduleName). "/App/Tables/{$this->modelName}Table.php" : app_path("Tables/{$this->modelName}Table.php"), 14 | [ 15 | "name" => "{$this->modelName}Table", 16 | "title" => $this->modelName, 17 | "model" => $this->moduleName ? "\\Modules\\".$this->moduleName."\\App\\Models\\".$this->modelName :"\\App\\Models\\".$this->modelName, 18 | "searchable" => $this->generateSearchable(), 19 | "cols" => $this->generateCols(), 20 | "namespace" => $this->moduleName ? "Modules\\".$this->moduleName."\\App\\Tables" : "App\\Tables", 21 | ], 22 | [ 23 | $this->moduleName ? module_path($this->moduleName)."/App/Tables" : app_path("Tables") 24 | ] 25 | ); 26 | } 27 | 28 | private function generateSearchable(): string 29 | { 30 | $searchable = ""; 31 | foreach($this->cols as $key=>$item){ 32 | if($item['unique']){ 33 | $searchable .= "'{$item['name']}',"; 34 | } 35 | else if($item['name'] === 'id'){ 36 | $searchable .= "'{$item['name']}',"; 37 | } 38 | else if($item['name'] === 'name'){ 39 | $searchable .= "'{$item['name']}',"; 40 | } 41 | else if($item['name'] === 'phone'){ 42 | $searchable .= "'{$item['name']}',"; 43 | } 44 | else if($item['name'] === 'email'){ 45 | $searchable .= "'{$item['name']}',"; 46 | } 47 | else if(($item['type'] === 'relation') && class_exists(Kirschbaum\PowerJoins\PowerJoins::class)){ 48 | $searchable .= "'".Str::remove('_id', $item['name']).".".$item['relation']['relationColumn']."',"; 49 | } 50 | } 51 | 52 | return $searchable; 53 | } 54 | 55 | private function generateCols(): string 56 | { 57 | $cols = ""; 58 | foreach($this->cols as $key=>$item){ 59 | if($item['name'] !== 'password'){ 60 | if($key!== 0){ 61 | $cols .= " "; 62 | } 63 | $cols .= $this->checkColumnForRelation($item); 64 | if($key!== count($this->cols)-1){ 65 | $cols .= PHP_EOL; 66 | } 67 | } 68 | } 69 | return $cols; 70 | } 71 | private function checkColumnForRelation(array $item){ 72 | $column="->column( 73 | key: '".$item['name']."', 74 | label: __('".Str::of($item['name'])->replace('_',' ')->ucfirst()."'), 75 | sortable: true 76 | )"; 77 | if ($item['type'] == 'relation' && class_exists(Kirschbaum\PowerJoins\PowerJoins::class)){ 78 | $column= "->column( 79 | key: '".Str::remove('_id', $item['name']).".".$item['relation']['relationColumn']."', 80 | label: __('".Str::of($item['name'])->remove('_id')->replace('_',' ')->ucfirst()."'), 81 | sortable: true, 82 | searchable: true 83 | )"; 84 | } 85 | return $column; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/Services/Generator/Concerns/InjectString.php: -------------------------------------------------------------------------------- 1 | $replacement){ 18 | $convertStubToText = $convertStubToText->replace('{{ '.$key.' }}',$replacement); 19 | } 20 | 21 | $content = \Illuminate\Support\Facades\File::get($file); 22 | $fileToString = Str::of($content); 23 | $fileToArray = $fileToString->explode("\n"); 24 | $pos = 0; 25 | $fileToArray->each(function ($line, $key) use (&$pos, $find, $plus){ 26 | if(Str::contains($line, $find)){ 27 | $pos = $key + $plus; 28 | } 29 | }); 30 | 31 | $newArray = array_slice($fileToArray->toArray(), 0, $pos, true) + 32 | array("value" =>"\n". $convertStubToText->toString()."\n") + 33 | array_slice($fileToArray->toArray(), $pos, count($fileToArray->toArray()) - 1, true) ; 34 | 35 | $replaceToArray = explode("\n", $convertStubToText->toString()); 36 | if(!array_search($replaceToArray[0], $newArray)){ 37 | $fileToString = implode("\n", $newArray); 38 | \Illuminate\Support\Facades\File::put($file, $fileToString); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/TomatoPHPServiceProvider.php: -------------------------------------------------------------------------------- 1 | mergeConfigFrom( 25 | __DIR__.'/../config/tomato-php.php', 'tomato-php' 26 | ); 27 | $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'tomato-php'); 28 | $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); 29 | $this->commands([ 30 | TomatoGenerator::class, 31 | TomatoGeneratorControllers::class, 32 | TomatoGeneratorForm::class, 33 | TomatoGeneratorModels::class, 34 | TomatoGeneratorRoutes::class, 35 | TomatoGeneratorTables::class, 36 | TomatoGeneratorViews::class, 37 | TomatoGeneratorMenus::class 38 | ]); 39 | 40 | //publish stubs to the base folder 41 | $this->publishes([ 42 | __DIR__.'/../stubs' => base_path('stubs'), 43 | ], 'tomato-stubs'); 44 | 45 | //publish config file to config folder 46 | $this->publishes([ 47 | __DIR__.'/../config/tomato-php.php' => config_path('tomato-php.php'), 48 | ], 'tomato-config'); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /stubs/FormBuilder/BuilderController.stub: -------------------------------------------------------------------------------- 1 | model = {{ model }}::class; 19 | } 20 | 21 | /** 22 | * @param Request $request 23 | * @return View|JsonResponse 24 | */ 25 | public function index(Request $request): View 26 | { 27 | return Tomato::index( 28 | request: $request, 29 | model: $this->model, 30 | view: '{{ modulePath }}{{ table }}.index', 31 | table: {{ tableClass }}::class 32 | ); 33 | } 34 | 35 | /** 36 | * @param Request $request 37 | * @return JsonResponse 38 | */ 39 | public function api(Request $request): JsonResponse 40 | { 41 | return Tomato::json( 42 | request: $request, 43 | model: {{ model }}::class, 44 | ); 45 | } 46 | 47 | /** 48 | * @return View 49 | */ 50 | public function create(): View 51 | { 52 | return Tomato::create( 53 | view: '{{ modulePath }}{{ table }}.form', 54 | data: ['form'=>{{ formClass }}::class] 55 | ); 56 | } 57 | 58 | /** 59 | * @param Request $request 60 | * @return RedirectResponse|JsonResponse 61 | */ 62 | public function store(Request $request): RedirectResponse|JsonResponse 63 | { 64 | $response = Tomato::store( 65 | request: $request, 66 | model: {{ model }}::class, 67 | validation: [ 68 | {{ validation }} 69 | ], 70 | message: __('{{ title }} updated successfully'), 71 | redirect: 'admin.{{ table }}.index', 72 | ); 73 | 74 | if($response instanceof JsonResponse){ 75 | return $response; 76 | } 77 | 78 | return $response->redirect; 79 | } 80 | 81 | /** 82 | * @param {{ model }} $model 83 | * @return View|JsonResponse 84 | */ 85 | public function show({{ model }} $model): View|JsonResponse 86 | { 87 | return Tomato::get( 88 | model: $model, 89 | view: '{{ modulePath }}{{ table }}.show', 90 | ); 91 | } 92 | 93 | /** 94 | * @param {{ model }} $model 95 | * @return View 96 | */ 97 | public function edit({{ model }} $model): View 98 | { 99 | {{ formClass }}::$model=$model; 100 | {{ formClass }}::$route="admin.{{ table }}.update"; 101 | 102 | return Tomato::get( 103 | model: $model, 104 | view: '{{ modulePath }}{{ table }}.form', 105 | data: ['form'=>{{ formClass }}::class] 106 | ); 107 | } 108 | 109 | /** 110 | * @param Request $request 111 | * @param {{ model }} $model 112 | * @return RedirectResponse|JsonResponse 113 | */ 114 | public function update(Request $request, {{ model }} $model): RedirectResponse|JsonResponse 115 | { 116 | $response = Tomato::update( 117 | request: $request, 118 | model: $model, 119 | validation: [ 120 | {{ validationEdit }} 121 | ], 122 | message: __('{{ title }} updated successfully'), 123 | redirect: 'admin.{{ table }}.index', 124 | ); 125 | 126 | if($response instanceof JsonResponse){ 127 | return $response; 128 | } 129 | 130 | return $response->redirect; 131 | } 132 | 133 | /** 134 | * @param {{ model }} $model 135 | * @return RedirectResponse|JsonResponse 136 | */ 137 | public function destroy({{ model }} $model): RedirectResponse|JsonResponse 138 | { 139 | $response = Tomato::destroy( 140 | model: $model, 141 | message: __('{{ title }} deleted successfully'), 142 | redirect: 'admin.{{ table }}.index', 143 | ); 144 | 145 | if($response instanceof JsonResponse){ 146 | return $response; 147 | } 148 | 149 | return $response->redirect; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /stubs/FormBuilder/Form.stub: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /stubs/FormBuilder/FormClass.stub: -------------------------------------------------------------------------------- 1 | action(route(self::$route,self::$model)) 20 | ->method('POST') 21 | ->class('space-y-4') 22 | ->fill(self::$model); 23 | 24 | } 25 | 26 | public function fields(): array 27 | { 28 | return [ 29 | {{ cols }} 30 | Submit::make() 31 | ->label(__('Save')), 32 | ]; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /stubs/api-route.stub: -------------------------------------------------------------------------------- 1 | 2 | Route::middleware(['auth:sanctum'])->name('api.')->group(function () { 3 | Route::get('/{{ table }}', [{{ name }}::class, 'index'])->name('{{ table }}.index'); 4 | Route::post('/{{ table }}', [{{ name }}::class, 'store'])->name('{{ table }}.store'); 5 | Route::get('/{{ table }}/{model}', [{{ name }}::class, 'show'])->name('{{ table }}.show'); 6 | Route::post('/{{ table }}/{model}', [{{ name }}::class, 'update'])->name('{{ table }}.update'); 7 | Route::delete('/{{ table }}/{model}', [{{ name }}::class, 'destroy'])->name('{{ table }}.destroy'); 8 | }); 9 | -------------------------------------------------------------------------------- /stubs/casts.stub: -------------------------------------------------------------------------------- 1 | protected $casts = [ 2 | {{ casts }} 3 | ]; 4 | -------------------------------------------------------------------------------- /stubs/controller-request.stub: -------------------------------------------------------------------------------- 1 | model = {{ model }}::class; 19 | } 20 | 21 | /** 22 | * @param Request $request 23 | * @return View|JsonResponse 24 | */ 25 | public function index(Request $request): View|JsonResponse 26 | { 27 | return Tomato::index( 28 | request: $request, 29 | model: $this->model, 30 | view: '{{ modulePath }}{{ table }}.index', 31 | table: {{ tableClass }}::class 32 | ); 33 | } 34 | 35 | /** 36 | * @param Request $request 37 | * @return JsonResponse 38 | */ 39 | public function api(Request $request): JsonResponse 40 | { 41 | return Tomato::json( 42 | request: $request, 43 | model: {{ model }}::class, 44 | ); 45 | } 46 | 47 | /** 48 | * @return View 49 | */ 50 | public function create(): View 51 | { 52 | return Tomato::create( 53 | view: '{{ modulePath }}{{ table }}.create', 54 | ); 55 | } 56 | 57 | /** 58 | * @param {{ requestNamespace }}{{ title }}StoreRequest $request 59 | * @return RedirectResponse|JsonResponse 60 | */ 61 | public function store({{ requestNamespace }}{{ title }}StoreRequest $request): RedirectResponse|JsonResponse 62 | { 63 | $response = Tomato::store( 64 | request: $request, 65 | model: {{ model }}::class, 66 | message: __('{{ title }} updated successfully'), 67 | redirect: 'admin.{{ table }}.index', 68 | ); 69 | 70 | if($response instanceof JsonResponse){ 71 | return $response; 72 | } 73 | 74 | return $response->redirect; 75 | } 76 | 77 | /** 78 | * @param {{ model }} $model 79 | * @return View|JsonResponse 80 | */ 81 | public function show({{ model }} $model): View|JsonResponse 82 | { 83 | return Tomato::get( 84 | model: $model, 85 | view: '{{ modulePath }}{{ table }}.show', 86 | ); 87 | } 88 | 89 | /** 90 | * @param {{ model }} $model 91 | * @return View 92 | */ 93 | public function edit({{ model }} $model): View 94 | { 95 | return Tomato::get( 96 | model: $model, 97 | view: '{{ modulePath }}{{ table }}.edit', 98 | ); 99 | } 100 | 101 | /** 102 | * @param {{ requestNamespace }}{{ title }}UpdateRequest $request 103 | * @param {{ model }} $model 104 | * @return RedirectResponse|JsonResponse 105 | */ 106 | public function update({{ requestNamespace }}{{ title }}UpdateRequest $request, {{ model }} $model): RedirectResponse|JsonResponse 107 | { 108 | $response = Tomato::update( 109 | request: $request, 110 | model: $model, 111 | message: __('{{ title }} updated successfully'), 112 | redirect: 'admin.{{ table }}.index', 113 | ); 114 | 115 | if($response instanceof JsonResponse){ 116 | return $response; 117 | } 118 | 119 | return $response->redirect; 120 | } 121 | 122 | /** 123 | * @param {{ model }} $model 124 | * @return RedirectResponse|JsonResponse 125 | */ 126 | public function destroy({{ model }} $model): RedirectResponse|JsonResponse 127 | { 128 | $response = Tomato::destroy( 129 | model: $model, 130 | message: __('{{ title }} deleted successfully'), 131 | redirect: 'admin.{{ table }}.index', 132 | ); 133 | 134 | if($response instanceof JsonResponse){ 135 | return $response; 136 | } 137 | 138 | return $response->redirect; 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /stubs/controller.stub: -------------------------------------------------------------------------------- 1 | model = {{ model }}::class; 19 | } 20 | 21 | /** 22 | * @param Request $request 23 | * @return View|JsonResponse 24 | */ 25 | public function index(Request $request): View|JsonResponse 26 | { 27 | return Tomato::index( 28 | request: $request, 29 | model: $this->model, 30 | view: '{{ modulePath }}{{ table }}.index', 31 | table: {{ tableClass }}::class 32 | ); 33 | } 34 | 35 | /** 36 | * @param Request $request 37 | * @return JsonResponse 38 | */ 39 | public function api(Request $request): JsonResponse 40 | { 41 | return Tomato::json( 42 | request: $request, 43 | model: {{ model }}::class, 44 | ); 45 | } 46 | 47 | /** 48 | * @return View 49 | */ 50 | public function create(): View 51 | { 52 | return Tomato::create( 53 | view: '{{ modulePath }}{{ table }}.create', 54 | ); 55 | } 56 | 57 | /** 58 | * @param Request $request 59 | * @return RedirectResponse|JsonResponse 60 | */ 61 | public function store(Request $request): RedirectResponse|JsonResponse 62 | { 63 | $response = Tomato::store( 64 | request: $request, 65 | model: {{ model }}::class, 66 | validation: [ 67 | {{ validation }} 68 | ], 69 | message: __('{{ title }} updated successfully'), 70 | redirect: 'admin.{{ table }}.index', 71 | ); 72 | 73 | if($response instanceof JsonResponse){ 74 | return $response; 75 | } 76 | 77 | return $response->redirect; 78 | } 79 | 80 | /** 81 | * @param {{ model }} $model 82 | * @return View|JsonResponse 83 | */ 84 | public function show({{ model }} $model): View|JsonResponse 85 | { 86 | return Tomato::get( 87 | model: $model, 88 | view: '{{ modulePath }}{{ table }}.show', 89 | ); 90 | } 91 | 92 | /** 93 | * @param {{ model }} $model 94 | * @return View 95 | */ 96 | public function edit({{ model }} $model): View 97 | { 98 | return Tomato::get( 99 | model: $model, 100 | view: '{{ modulePath }}{{ table }}.edit', 101 | ); 102 | } 103 | 104 | /** 105 | * @param Request $request 106 | * @param {{ model }} $model 107 | * @return RedirectResponse|JsonResponse 108 | */ 109 | public function update(Request $request, {{ model }} $model): RedirectResponse|JsonResponse 110 | { 111 | $response = Tomato::update( 112 | request: $request, 113 | model: $model, 114 | validation: [ 115 | {{ validationEdit }} 116 | ], 117 | message: __('{{ title }} updated successfully'), 118 | redirect: 'admin.{{ table }}.index', 119 | ); 120 | 121 | if($response instanceof JsonResponse){ 122 | return $response; 123 | } 124 | 125 | return $response->redirect; 126 | } 127 | 128 | /** 129 | * @param {{ model }} $model 130 | * @return RedirectResponse|JsonResponse 131 | */ 132 | public function destroy({{ model }} $model): RedirectResponse|JsonResponse 133 | { 134 | $response = Tomato::destroy( 135 | model: $model, 136 | message: __('{{ title }} deleted successfully'), 137 | redirect: 'admin.{{ table }}.index', 138 | ); 139 | 140 | if($response instanceof JsonResponse){ 141 | return $response; 142 | } 143 | 144 | return $response->redirect; 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /stubs/create.stub: -------------------------------------------------------------------------------- 1 | 2 | 3 | {{ cols }} 4 | 5 |
6 | 7 | 8 |
9 |
10 |
11 | -------------------------------------------------------------------------------- /stubs/edit.stub: -------------------------------------------------------------------------------- 1 | 2 | 3 | {{ cols }} 4 | 5 |
6 | 7 | 13 | 14 |
15 |
16 |
17 | -------------------------------------------------------------------------------- /stubs/index.stub: -------------------------------------------------------------------------------- 1 | 2 | 3 | {{ __('{{ title }}') }} 4 | 5 | 6 | 7 | {{trans('tomato-admin::global.crud.create-new')}} {{__('{{ title }}')}} 8 | 9 | 10 | 11 |
12 |
13 | 14 | {{ cells }} 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 | 30 | 31 | 32 |
33 |
34 |
35 |
36 |
37 |
38 | -------------------------------------------------------------------------------- /stubs/json.stub: -------------------------------------------------------------------------------- 1 | group('{{ moduleName }}') 4 | ->label('{{ title }}') 5 | ->icon('bx bx-circle') 6 | ->route('admin.{{ tableName }}.index'), 7 | ]); 8 | -------------------------------------------------------------------------------- /stubs/request.stub: -------------------------------------------------------------------------------- 1 | 23 | */ 24 | public function rules() 25 | { 26 | return [ 27 | {{ validation }} 28 | ]; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /stubs/route.stub: -------------------------------------------------------------------------------- 1 | 2 | Route::middleware(['auth', 'splade', 'verified'])->name('admin.')->group(function () { 3 | Route::get('admin/{{ table }}', [{{ name }}::class, 'index'])->name('{{ table }}.index'); 4 | Route::get('admin/{{ table }}/api', [{{ name }}::class, 'api'])->name('{{ table }}.api'); 5 | Route::get('admin/{{ table }}/create', [{{ name }}::class, 'create'])->name('{{ table }}.create'); 6 | Route::post('admin/{{ table }}', [{{ name }}::class, 'store'])->name('{{ table }}.store'); 7 | Route::get('admin/{{ table }}/{model}', [{{ name }}::class, 'show'])->name('{{ table }}.show'); 8 | Route::get('admin/{{ table }}/{model}/edit', [{{ name }}::class, 'edit'])->name('{{ table }}.edit'); 9 | Route::post('admin/{{ table }}/{model}', [{{ name }}::class, 'update'])->name('{{ table }}.update'); 10 | Route::delete('admin/{{ table }}/{model}', [{{ name }}::class, 'destroy'])->name('{{ table }}.destroy'); 11 | }); 12 | -------------------------------------------------------------------------------- /stubs/table.stub: -------------------------------------------------------------------------------- 1 | query = {{ model }}::query(); 22 | } 23 | } 24 | 25 | /** 26 | * Determine if the user is authorized to perform bulk actions and exports. 27 | * 28 | * @return bool 29 | */ 30 | public function authorize(Request $request) 31 | { 32 | return true; 33 | } 34 | 35 | /** 36 | * The resource or query builder. 37 | * 38 | * @return mixed 39 | */ 40 | public function for() 41 | { 42 | return $this->query; 43 | } 44 | 45 | /** 46 | * Configure the given SpladeTable. 47 | * 48 | * @param \ProtoneMedia\Splade\SpladeTable $table 49 | * @return void 50 | */ 51 | public function configure(SpladeTable $table) 52 | { 53 | $table 54 | ->withGlobalSearch( 55 | label: trans('tomato-admin::global.search'), 56 | columns: [{{ searchable }}] 57 | ) 58 | ->bulkAction( 59 | label: trans('tomato-admin::global.crud.delete'), 60 | each: fn ({{ model }} $model) => $model->delete(), 61 | after: fn () => Toast::danger(__('{{ title }} Has Been Deleted'))->autoDismiss(2), 62 | confirm: true 63 | ) 64 | ->defaultSort('id', 'desc') 65 | {{ cols }} 66 | ->column(key: 'actions',label: trans('tomato-admin::global.crud.actions')) 67 | ->export() 68 | ->paginate(10); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /stubs/view.stub: -------------------------------------------------------------------------------- 1 | 2 |
3 | {{ cols }} 4 |
5 |
6 | 7 | 13 | 14 |
15 |
16 | -------------------------------------------------------------------------------- /tests/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/tomato-php/4ecec3677c28c7a7ec8352e7627095ed955233bb/tests/.gitkeep --------------------------------------------------------------------------------