├── .gitattributes ├── LICENSE ├── README.md ├── composer.json ├── config └── wovosoft-crud.php ├── skeleton ├── .coveralls.yml ├── .editorconfig ├── .gitattributes.tpl ├── .gitignore.tpl ├── .styleci.yml ├── .travis.yml ├── LICENSE.tpl ├── README.md.tpl ├── composer.json.tpl ├── phpunit.xml └── src │ └── ServiceProvider.php.tpl ├── src ├── Commands │ ├── CrudCommand.php │ ├── MakeController.php │ ├── MakeModel.php │ ├── PackageNew.php │ ├── PackageRemove.php │ ├── RemoveController.php │ ├── RemoveModel.php │ └── Traits │ │ ├── ChangesComposerJson.php │ │ ├── CopiesSkeleton.php │ │ ├── InteractsWithComposer.php │ │ ├── InteractsWithGit.php │ │ ├── InteractsWithUser.php │ │ └── ManipulatesPackageFolder.php ├── Exceptions │ └── RuntimeException.php └── ServiceProvider.php └── stubs ├── Controller.php.tpl ├── Facade.php.tpl ├── MainClass.php.tpl ├── MainClassTest.php.tpl ├── Model.php.tpl ├── config.php ├── routes.php.tpl └── seeder.stub /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Narayan Chandra Adhikary 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 all 13 | 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Laravel Package Generator 2 | ========================= 3 | 4 | [![Latest Stable Version](https://poser.pugx.org/wovosoft/crud/v/stable)](https://packagist.org/packages/wovosoft/crud) [![Total Downloads](https://poser.pugx.org/wovosoft/crud/downloads)](https://packagist.org/packages/wovosoft/crud) [![Latest Unstable Version](https://poser.pugx.org/wovosoft/crud/v/unstable)](https://packagist.org/packages/wovosoft/crud) [![License](https://poser.pugx.org/wovosoft/crud/license)](https://packagist.org/packages/wovosoft/crud) 5 | 6 | # Simple package to quickly generate basic structure for laravel packages. 7 | 8 | ## Install 9 | 10 | Install via composer 11 | ```bash 12 | composer require --dev wovosoft/crud 13 | ``` 14 | 15 | Publish package config if you want customize default values 16 | ```bash 17 | php artisan vendor:publish --provider="Wovosoft\Crud\ServiceProvider" --tag="config" 18 | ``` 19 | 20 | ## Available commands for Packages 21 | 22 | ### Make A New Package 23 | `php artisan crud:make_package {vendor} {package}` \ 24 | or, with inraction\ 25 | `php artisan crud:make_package -i` 26 | 27 | 28 | Example: `php artisan crud:make_package Wovosoft SomeAwesomePackage` 29 | 30 | This command will: 31 | 32 | * Create `packages/wovosoft/some-awesome-package` folder 33 | * Register package in app composer.json 34 | * Copy package skeleton from skeleton folder to created folder (you can provide 35 | your custom skeleton path in config) 36 | * Run `git init packages/wovosoft/some-awesome-package` 37 | * Run `composer update wovosoft/some-awesome-package` 38 | * Run `composer dump-autoload` 39 | 40 | With interactive `-i` flag you will be prompted for every needed value from you. 41 | 42 | ### Remove A Package 43 | `php artisan crud:remove_package {vendor} {package} ` 44 | 45 | Example: `php artisan crud:remove_package Wovosoft SomeAwesomePackage` 46 | 47 | This command will: 48 | 49 | * Run `composer remove wovosoft/some-awesome-package` 50 | * Remove `packages/wovosoft/some-awesome-package` folder 51 | * Unregister package in app composer.json 52 | * Run `composer dump-autoload` 53 | 54 | **Interactive mode also possible.** 55 | ## Available Commands For Controller Generation 56 | ### Make a Controller 57 | `php artisan crud:make_controller {vendor} {package} {controller} {model}` \ 58 | 59 | #### With Interaction Mode 60 | `php artisan crud:make_controller -i` 61 | 62 | ### Remove A Controller 63 | `php artisan crud:remove_controller {vendor} {package} {controller}` 64 | #### With Interaction Mode 65 | `php artisan crud:remove_controller -i` 66 | 67 | ## Available Commands for Model Generation 68 | ### Make a Model 69 | `php artisan crud:make_model {vendor} {package} {model}` 70 | #### With Interaction Mode 71 | `php artisan crud:make_model -i` 72 | ### Remove a Model 73 | `php artisan crud:remove_model {vendor} {package} {model}` 74 | #### With Interaction Model 75 | `php artisan crud:remove_model -i` 76 | 77 | ## CRUD Console Application 78 | > There is a Console Application available. To run all above Artisan Commands from a single terminal with less commands, please run `php artisan crud -i` or `php artisan crud`. Then you can see the all available commands in a multiple choice form. Just select an option and that command will start executing immediately in interaction mode. You can then follow the rest of the ongoing processes. 79 | 80 | ## Custom skeleton 81 | > This package will copy all folders and files from specified skeleton path to package folder. You can use templates in your skeleton. All files with `tpl` extension will be provided with some variables available to use in them. `tpl` extension will be stripped. 82 | 83 | ### Available variables to use in templates: 84 | 85 | * vendor (e.g. Wovosoft) 86 | * package (e.g. SomeAwesomePackage) 87 | * vendorFolderName (e.g. wovosoft) 88 | * packageFolderName (e.g. some-awesome-package) 89 | * packageHumanName (e.g. Some awesome package) 90 | * composerName (e.g. wovosoft/some-awesome-package) 91 | * composerDesc (e.g. A some awesome package) 92 | * composerKeywords (e.g. some,awesome,package) 93 | * licence (e.g. MIT) 94 | * phpVersion (e.g. >=7.0) 95 | * aliasName (e.g. some-awesome-package) 96 | * configFileName (e.g. some-awesome-package) 97 | * year (e.g. 2017) 98 | * name (e.g. Narayan Adhikary) 99 | * email (e.g. narayanadhikary24@gmail.com) 100 | * githubPackageUrl (e.g. https://github.com/wovosoft/some-awesome-package) 101 | * controller (Name of the Controller for Controller Generation) 102 | * model (Name of the Model for Model Generation) 103 | 104 | ## Things you need to do manually: 105 | 106 | * Service provider and alias registration (if you use laravel <5.5) 107 | * In README.md: 108 | * StyleCI repository identifier 109 | * Package description 110 | * Usage section 111 | 112 | ## Security 113 | 114 | If you discover any security related issues, please email narayanadhikary24@gmail.com Or, create an issue in this github repository. 115 | 116 | ## Credits 117 | 118 | - [Narayan Adhikary](https://github.com/narai420) 119 | - [Wovo Soft](https://gitlab.com/wovosoft) 120 | 121 | ## Special Thanks 122 | - Special Thanks to https://github.com/melihovv/laravel-package-generator . We have just made an extended version of this package. A Console Application is integrated to perform all operations. Few more commands like Controller, Models with adding and removing features for certain packages are added. 123 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wovosoft/crud", 3 | "description": "A laravel package generator for WovoCMS", 4 | "license": "MIT", 5 | "keywords": [ 6 | "laravel", 7 | "package", 8 | "generator", 9 | "controllers", 10 | "models", 11 | "seeders" 12 | ], 13 | "type": "library", 14 | "authors": [ 15 | { 16 | "name": "Narayan Adhikary", 17 | "email": "narayanahdikary24@gmail.com" 18 | }, 19 | { 20 | "name": "WovoSoft Developer Team", 21 | "email": "wovosoft@gmail.com" 22 | } 23 | ], 24 | "require": { 25 | "php": ">=7.2", 26 | "illuminate/container": "^7.0", 27 | "illuminate/console": "^7.0", 28 | "illuminate/filesystem": "^7.0", 29 | "illuminate/support": "^7.0", 30 | "illuminate/view": "^7.0" 31 | }, 32 | "autoload": { 33 | "psr-4": { 34 | "Wovosoft\\Crud\\": "src" 35 | } 36 | }, 37 | "extra": { 38 | "laravel": { 39 | "providers": [ 40 | "Wovosoft\\Crud\\ServiceProvider" 41 | ] 42 | } 43 | }, 44 | "config": { 45 | "preferred-install": "dist", 46 | "sort-packages": true, 47 | "optimize-autoloader": true 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /config/wovosoft-crud.php: -------------------------------------------------------------------------------- 1 | null, 16 | 'init_git_onCreate' => false, 17 | 'register_package_to_composer_dot_json' => true, 18 | 'composer_update_onCreate' => true, 19 | 'composer_dumpAutoload_onCreate' => true, 20 | 'directories_to_create' => [ 21 | "database/migrations", 22 | "database/factories", 23 | "database/seeds", 24 | "src/Traits", 25 | "src/Models", 26 | "src/Http/Controllers", 27 | "resources/js", 28 | "resources/lang", 29 | "resources/views", 30 | ] 31 | 32 | ]; 33 | -------------------------------------------------------------------------------- /skeleton/.coveralls.yml: -------------------------------------------------------------------------------- 1 | coverage_clover: tests/logs/clover.xml 2 | json_path: tests/logs/coveralls-upload.json 3 | service_name: travis-ci 4 | -------------------------------------------------------------------------------- /skeleton/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [Makefile] 12 | indent_style = tab 13 | 14 | [*.php] 15 | indent_size = 4 16 | -------------------------------------------------------------------------------- /skeleton/.gitattributes.tpl: -------------------------------------------------------------------------------- 1 | * text=auto 2 | /.github export-ignore 3 | /tests export-ignore 4 | /.editorconfig export-ignore 5 | /.gitattributes export-ignore 6 | /.gitignore export-ignore 7 | /.travis.yml export-ignore 8 | /.styleci.yml export-ignore 9 | /.sensiolabs.yml export-ignore 10 | /.coveralls.yml export-ignore 11 | /phpunit.xml export-ignore 12 | /CHANGELOG-* export-ignore 13 | /CONTRIBUTING.md export-ignore 14 | /CODE_OF_CONDUCT.md export-ignore 15 | -------------------------------------------------------------------------------- /skeleton/.gitignore.tpl: -------------------------------------------------------------------------------- 1 | /vendor 2 | /.idea 3 | /node_modules 4 | /composer.lock 5 | /.phpunit.result.cache 6 | -------------------------------------------------------------------------------- /skeleton/.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel 2 | -------------------------------------------------------------------------------- /skeleton/.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | sudo: false 4 | 5 | notifications: 6 | email: 7 | on_success: never 8 | on_failure: always 9 | 10 | matrix: 11 | include: 12 | - php: 7.2 13 | env: LARAVEL='6.*' TESTBENCH='4.*' COMPOSER_FLAGS='--prefer-lowest' 14 | - php: 7.2 15 | env: LARAVEL='6.*' TESTBENCH='4.*' COMPOSER_FLAGS='--prefer-stable' 16 | - php: 7.3 17 | env: LARAVEL='6.*' TESTBENCH='4.*' COMPOSER_FLAGS='--prefer-lowest' 18 | - php: 7.3 19 | env: LARAVEL='6.*' TESTBENCH='4.*' COMPOSER_FLAGS='--prefer-stable' 20 | - php: 7.4snapshot 21 | env: LARAVEL='6.*' TESTBENCH='4.*' COMPOSER_FLAGS='--prefer-lowest' 22 | - php: 7.4snapshot 23 | env: LARAVEL='6.*' TESTBENCH='4.*' COMPOSER_FLAGS='--prefer-stable' 24 | fast_finish: true 25 | allow_failures: 26 | - php: 7.4snapshot 27 | 28 | before_install: 29 | - composer config discard-changes true 30 | - composer validate --no-check-all --strict 31 | - travis_retry composer self-update 32 | - travis_retry composer require "laravel/framework:${LARAVEL}" "orchestra/testbench:${TESTBENCH}" --no-interaction --no-update 33 | 34 | install: 35 | - travis_retry composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction --no-suggest 36 | - travis_retry composer require --dev satooshi/php-coveralls 37 | 38 | script: 39 | - composer run phpunit -- --coverage-clover ./tests/logs/clover.xml 40 | 41 | after_script: 42 | - php vendor/bin/php-coveralls -v 43 | -------------------------------------------------------------------------------- /skeleton/LICENSE.tpl: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) <> 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 all 13 | 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 THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /skeleton/README.md.tpl: -------------------------------------------------------------------------------- 1 | # 2 | 3 | [![Build Status](https://travis-ci.org//.svg?branch=master)](https://travis-ci.org//) 4 | [![styleci](https://styleci.io/repos/CHANGEME/shield)](https://styleci.io/repos/CHANGEME) 5 | [![Coverage Status](https://coveralls.io/repos/github///badge.svg?branch=master)](https://coveralls.io/github//?branch=master) 6 | 7 | [![Packagist](https://img.shields.io/packagist/v//.svg)](https://packagist.org/packages//) 8 | [![Packagist](https://poser.pugx.org///d/total.svg)](https://packagist.org/packages//) 9 | [![Packagist](https://img.shields.io/packagist/l//.svg)](https://packagist.org/packages//) 10 | 11 | Package description: CHANGE ME 12 | 13 | ## Installation 14 | 15 | Install via composer 16 | ```bash 17 | composer require / 18 | ``` 19 | 20 | ### Publish Configuration File 21 | 22 | ```bash 23 | php artisan vendor:publish --provider="\\ServiceProvider" --tag="config" 24 | ``` 25 | 26 | ## Usage 27 | 28 | CHANGE ME 29 | 30 | ## Security 31 | 32 | If you discover any security related issues, please email 33 | instead of using the issue tracker. 34 | 35 | ## Credits 36 | 37 | - []() 38 | - [All contributors](/graphs/contributors) 39 | 40 | This package is bootstrapped with the help of 41 | [wovosoft/crud](https://github.com/wovosoft/crud). 42 | -------------------------------------------------------------------------------- /skeleton/composer.json.tpl: -------------------------------------------------------------------------------- 1 | { 2 | "name": "", 3 | "description": "", 4 | "license": "", 5 | "keywords": [ 6 | 7 | ], 8 | "type": "library", 9 | "authors": [ 10 | { 11 | "name": "", 12 | "email": "" 13 | } 14 | ], 15 | "require": { 16 | "php": "", 17 | "illuminate/support": "^7.0" 18 | }, 19 | "require-dev": { 20 | "orchestra/testbench": "^4.0", 21 | "phpunit/phpunit": "^8.5" 22 | }, 23 | "autoload": { 24 | "psr-4": { 25 | "\\\\": "src" 26 | } 27 | }, 28 | "autoload-dev": { 29 | "psr-4": { 30 | "\\\\Tests\\": "tests" 31 | } 32 | }, 33 | "scripts": { 34 | "phpunit": "phpunit" 35 | }, 36 | "extra": { 37 | "laravel": { 38 | "providers": [ 39 | "\\\\ServiceProvider" 40 | ] 41 | } 42 | }, 43 | "config": { 44 | "preferred-install": "dist", 45 | "sort-packages": true, 46 | "optimize-autoloader": true 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /skeleton/phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | tests 14 | 15 | 16 | 17 | 18 | src 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /skeleton/src/ServiceProvider.php.tpl: -------------------------------------------------------------------------------- 1 | 2 | 3 | namespace \; 4 | 5 | class ServiceProvider extends \Illuminate\Support\ServiceProvider 6 | { 7 | const CONFIG_PATH = __DIR__ . '/../config/.php'; 8 | 9 | public function boot() 10 | { 11 | if ($this->app->runningInConsole()) { 12 | $this->publishes([ 13 | self::CONFIG_PATH => config_path('.php'), 14 | ], 'config'); 15 | } 16 | 17 | 18 | $this->loadMigrationsFrom(__DIR__ . "/../database/migrations"); 19 | $this->loadRoutesFrom(__DIR__ . "/routes.php"); 20 | $this->loadFactoriesFrom(__DIR__ . "/../database/factories"); 21 | $this->loadViewsFrom(__DIR__ . "/../resources/views", ''); 22 | $this->loadTranslationsFrom(__DIR__ . "/../resources/lang", ''); 23 | //$this->loadJsonTranslationsFrom(__DIR__."/../resources/lang"); 24 | } 25 | 26 | public function register() 27 | { 28 | $this->mergeConfigFrom( 29 | self::CONFIG_PATH, 30 | '' 31 | ); 32 | 33 | $this->app->bind('', function () { 34 | return new (); 35 | }); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Commands/CrudCommand.php: -------------------------------------------------------------------------------- 1 | getCommand(null); 43 | $this->call("crud:" . $type, [ 44 | "-i" => true 45 | ]); 46 | if ($this->choice("Do you want to run mode Commands?", [ 47 | "YES", 48 | "NO" 49 | ], 0) == "YES") { 50 | $this->call("crud", [ 51 | "-i" => true 52 | ]); 53 | } 54 | } 55 | 56 | protected function getCommand($default = null) 57 | { 58 | return $default ?? $this->choice( 59 | 'What do you want to generate?', 60 | [ 61 | "make_package", 62 | "remove_package", 63 | "make_model", 64 | "remove_model", 65 | "make_controller", 66 | "remove_controller", 67 | ], 0); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Commands/MakeController.php: -------------------------------------------------------------------------------- 1 | getVendor('vendor'); 53 | $package = $this->getPackage('package'); 54 | $model = $this->getModel('model'); 55 | $controller = $this->getController('controller'); 56 | 57 | 58 | $vendorFolderName = $this->getVendorFolderName($vendor); 59 | $packageFolderName = $this->getPackageFolderName($package); 60 | 61 | 62 | $relPackagePath = base_path("packages/$vendorFolderName/$packageFolderName/src/Http/Controllers/$controller.php.tpl"); 63 | $target = base_path("packages/$vendorFolderName/$packageFolderName/src/Http/Controllers/$controller.php"); 64 | 65 | if (File::exists($target)) { 66 | $this->warn('Controller Already Exits. Exiting...'); 67 | return; 68 | } 69 | if (!File::exists(dirname($relPackagePath))) { 70 | File::makeDirectory(dirname($relPackagePath), 0755, true); 71 | } 72 | if (!File::exists($relPackagePath)) { 73 | File::copy(__DIR__ . '/../../stubs/Controller.php.tpl', $relPackagePath); 74 | $this->info("Controller Stub copied to $relPackagePath"); 75 | } 76 | 77 | $this->info('Trying to parse the stub'); 78 | 79 | $phpEngine = app()->make(PhpEngine::class); 80 | try { 81 | $newFileContent = $phpEngine->get($relPackagePath, [ 82 | "vendor" => $vendor, 83 | "package" => $package, 84 | "controller" => $controller, 85 | "model" => $model, 86 | ]); 87 | } catch (\Exception $e) { 88 | $this->error("Template [$relPackagePath] contains syntax errors"); 89 | $this->error($e->getMessage()); 90 | $this->error("LINE # " . $e->getLine()); 91 | } 92 | $this->info("Stub Parsing Successful. Putting Parsed content to Controller File"); 93 | File::put($target, $newFileContent); 94 | File::delete($relPackagePath); 95 | 96 | $route_file = base_path("packages/$vendorFolderName/$packageFolderName" . "/src/routes.php"); 97 | if (File::exists($target) && File::exists($route_file)) { 98 | File::put($route_file, Str::replaceLast( 99 | "//MAPPING_AREA_FOR_CRUD_DO_NOT_REMOVE_OR_EDIT_THIS_LINE//", 100 | $vendor . "\\" . $package . "\\" . "Http\Controllers" . "\\" . $controller . "::routes();\n" . 101 | "\t\t//MAPPING_AREA_FOR_CRUD_DO_NOT_REMOVE_OR_EDIT_THIS_LINE//", 102 | File::get(base_path("packages/$vendorFolderName/$packageFolderName" . "/src/routes.php")) 103 | )); 104 | } 105 | $this->info("Stub File Deleted Successfully"); 106 | $this->info("Controller Created Successfully"); 107 | 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/Commands/MakeModel.php: -------------------------------------------------------------------------------- 1 | getVendor('vendor'); 50 | $package = $this->getPackage('package'); 51 | $model = $this->getModel('model'); 52 | $table = $this->getTable('table'); 53 | 54 | $vendorFolderName = $this->getVendorFolderName($vendor); 55 | $packageFolderName = $this->getPackageFolderName($package); 56 | 57 | $relPackagePath = base_path("packages/$vendorFolderName/$packageFolderName/src/Models/$model.php.tpl"); 58 | $target = base_path("packages/$vendorFolderName/$packageFolderName/src/Models/$model.php"); 59 | if (File::exists($target)) { 60 | $this->warn('Model Already Exits. Exiting...'); 61 | return; 62 | } 63 | if (!File::exists(dirname($relPackagePath))) { 64 | File::makeDirectory(dirname($relPackagePath), 0755, true); 65 | } 66 | if (!File::exists($relPackagePath)) { 67 | File::copy(__DIR__ . '/../../stubs/Model.php.tpl', $relPackagePath); 68 | $this->info("Model Stub copied to $relPackagePath"); 69 | } 70 | $this->info('Trying to parse the stub'); 71 | 72 | $phpEngine = app()->make(PhpEngine::class); 73 | try { 74 | $newFileContent = $phpEngine->get($relPackagePath, [ 75 | "vendor" => $vendor, 76 | "package" => $package, 77 | "model" => $model, 78 | "table" => $table 79 | ]); 80 | } catch (\Exception $e) { 81 | $this->error("Template [$relPackagePath] contains syntax errors"); 82 | $this->error($e->getMessage()); 83 | $this->error("LINE # " . $e->getLine()); 84 | } 85 | $this->info("Stub Parsing Successful. Putting Parsed content to Model file"); 86 | File::put($target, $newFileContent); 87 | File::delete($relPackagePath); 88 | $this->info("Stub File Deleted Successfully"); 89 | $this->info("Model Created Successfully"); 90 | 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/Commands/PackageNew.php: -------------------------------------------------------------------------------- 1 | getVendor(); 46 | $package = $this->getPackage(); 47 | 48 | $vendorFolderName = $this->getVendorFolderName($vendor); 49 | $packageFolderName = $this->getPackageFolderName($package); 50 | 51 | $relPackagePath = "packages/$vendorFolderName/$packageFolderName"; 52 | $packagePath = base_path($relPackagePath); 53 | 54 | try { 55 | if (!$vendor && !$package) { 56 | $this->warn("Vendor and Package name is required"); 57 | return false; 58 | } 59 | $this->createPackageFolder($packagePath); 60 | if (config('wovosoft-crud.register_package_to_composer_dot_json')) { 61 | $this->registerPackage($vendorFolderName, $packageFolderName, $relPackagePath); 62 | } 63 | 64 | $this->copySkeleton($packagePath, $vendor, $package, $vendorFolderName, $packageFolderName); 65 | 66 | if (config('wovosoft-crud.init_git_onCreate')) { 67 | $this->initRepo($packagePath); 68 | } 69 | if (config('wovosoft-crud.composer_update_onCreate')) { 70 | $this->composerUpdatePackage($vendorFolderName, $packageFolderName); 71 | } 72 | if (config('wovosoft-crud.composer_dumpAutoload_onCreate')) { 73 | $this->composerDumpAutoload(); 74 | } 75 | 76 | 77 | $this->info('Finished. Are you ready to write awesome package?'); 78 | 79 | return 0; 80 | } catch (Exception $e) { 81 | $this->error($e->getMessage()); 82 | 83 | return -1; 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/Commands/PackageRemove.php: -------------------------------------------------------------------------------- 1 | getVendor(); 44 | $package = $this->getPackage(); 45 | 46 | $vendorFolderName = $this->getVendorFolderName($vendor); 47 | $packageFolderName = $this->getPackageFolderName($package); 48 | 49 | $relPackagePath = "packages/$vendorFolderName/$packageFolderName"; 50 | $packagePath = base_path($relPackagePath); 51 | 52 | try { 53 | $this->composerRemovePackage($vendorFolderName, $packageFolderName); 54 | $this->removePackageFolder($packagePath); 55 | $this->unregisterPackage($vendor, $package, "packages/$vendorFolderName/$packageFolderName"); 56 | $this->composerDumpAutoload(); 57 | 58 | return 0; 59 | } catch (Exception $e) { 60 | $this->error($e->getMessage()); 61 | 62 | return -1; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Commands/RemoveController.php: -------------------------------------------------------------------------------- 1 | getVendor('vendor'); 50 | $package = $this->getPackage('package'); 51 | $controller = $this->getController('controller'); 52 | 53 | 54 | $vendorFolderName = $this->getVendorFolderName($vendor); 55 | $packageFolderName = $this->getPackageFolderName($package); 56 | 57 | 58 | $target = base_path("packages/$vendorFolderName/$packageFolderName/src/Http/Controllers/$controller.php"); 59 | 60 | if (!File::exists($target)) { 61 | $this->warn("Controller Doesn't Exists"); 62 | return; 63 | } 64 | 65 | try { 66 | $this->info('Trying to delete the controller file...'); 67 | if (File::delete($target)) { 68 | $this->info("$target Controller Deleted Successfully."); 69 | $route_file = base_path("packages/$vendorFolderName/$packageFolderName" . "/src/routes.php"); 70 | $this->info("Trying to delete $target reference from $route_file"); 71 | if (File::exists($route_file) && File::put($route_file, Str::replaceLast( 72 | $vendor . "\\" . $package . "\\" . "Http\Controllers" . "\\" . $controller . "::routes();", 73 | "", 74 | File::get($route_file)) 75 | )) { 76 | $this->info("Controller routes successfully deleted from $route_file"); 77 | } else { 78 | $this->error("Unable to delete Controller routes from $route_file.\nPlease Check Manually."); 79 | } 80 | } else { 81 | $this->error("Unable to delete $target Controller."); 82 | } 83 | } catch (\Exception $e) { 84 | $this->error($e->getMessage()); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/Commands/RemoveModel.php: -------------------------------------------------------------------------------- 1 | getVendor('vendor'); 49 | $package = $this->getPackage('package'); 50 | $model = $this->getModel('model'); 51 | 52 | 53 | $vendorFolderName = $this->getVendorFolderName($vendor); 54 | $packageFolderName = $this->getPackageFolderName($package); 55 | 56 | 57 | $target = base_path("packages/$vendorFolderName/$packageFolderName/src/Models/$model.php"); 58 | 59 | if (!File::exists($target)) { 60 | $this->warn("Model Doesn't Exists"); 61 | return; 62 | } 63 | 64 | try { 65 | $this->info('Trying to delete the model file...'); 66 | if (File::delete($target)) { 67 | $this->info("$target Model Deleted Successfully."); 68 | } else { 69 | $this->error("Unable to delete $target Model."); 70 | } 71 | } catch (\Exception $e) { 72 | $this->error($e->getMessage()); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/Commands/Traits/ChangesComposerJson.php: -------------------------------------------------------------------------------- 1 | info('Register package in composer.json.'); 25 | 26 | $composerJson = $this->loadComposerJson(); 27 | 28 | if (!isset($composerJson['repositories'])) { 29 | Arr::set($composerJson, 'repositories', []); 30 | } 31 | 32 | $filtered = array_filter($composerJson['repositories'], function ($repository) use ($relPackagePath) { 33 | return $repository['type'] === 'path' 34 | && $repository['url'] === $relPackagePath; 35 | }); 36 | 37 | if (count($filtered) === 0) { 38 | $this->info('Register composer repository for package.'); 39 | 40 | $composerJson['repositories']["$vendor/$package"] = (object)[ 41 | 'type' => 'path', 42 | 'url' => "./$relPackagePath", 43 | ]; 44 | } else { 45 | $this->info('Composer repository for package is already registered.'); 46 | } 47 | 48 | Arr::set($composerJson, "require.$vendor/$package", 'dev-master'); 49 | 50 | $this->saveComposerJson($composerJson); 51 | 52 | $this->info('Package was successfully registered in composer.json.'); 53 | } 54 | 55 | /** 56 | * Unregister package from composer.json. 57 | * 58 | * @param $vendor 59 | * @param $package 60 | * 61 | * @throws FileNotFoundException 62 | * @throws RuntimeException 63 | */ 64 | protected function unregisterPackage($vendor, $package, $relPackagePath) 65 | { 66 | $this->info('Unregister package from composer.json.'); 67 | 68 | $composerJson = $this->loadComposerJson(); 69 | 70 | unset($composerJson['require']["$vendor\\$package\\"]); 71 | 72 | $repositories = array_filter($composerJson['repositories'], function ($repository) use ($relPackagePath) { 73 | return $repository['type'] !== 'path' 74 | || $repository['url'] !== $relPackagePath; 75 | }); 76 | 77 | $composerJson['repositories'] = $repositories; 78 | 79 | if (count($composerJson['repositories']) === 0) { 80 | unset($composerJson['repositories']); 81 | } 82 | 83 | $this->saveComposerJson($composerJson); 84 | 85 | $this->info('Package was successfully unregistered from composer.json.'); 86 | } 87 | 88 | /** 89 | * Load and parse content of composer.json. 90 | * 91 | * @return array 92 | * 93 | * @throws FileNotFoundException 94 | * @throws RuntimeException 95 | */ 96 | protected function loadComposerJson() 97 | { 98 | $composerJsonPath = $this->getComposerJsonPath(); 99 | 100 | if (!File::exists($composerJsonPath)) { 101 | throw new FileNotFoundException('composer.json does not exist'); 102 | } 103 | 104 | $composerJsonContent = File::get($composerJsonPath); 105 | $composerJson = json_decode($composerJsonContent, true); 106 | 107 | if (!is_array($composerJson)) { 108 | throw new RuntimeException("Invalid composer.json file [$composerJsonPath]"); 109 | } 110 | 111 | return $composerJson; 112 | } 113 | 114 | /** 115 | * @param array $composerJson 116 | * 117 | * @throws RuntimeException 118 | */ 119 | protected function saveComposerJson($composerJson) 120 | { 121 | $newComposerJson = json_encode( 122 | $composerJson, 123 | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES 124 | ); 125 | 126 | $composerJsonPath = $this->getComposerJsonPath(); 127 | if (File::put($composerJsonPath, $newComposerJson) === false) { 128 | throw new RuntimeException("Cannot write to composer.json [$composerJsonPath]"); 129 | } 130 | } 131 | 132 | /** 133 | * Get composer.json path. 134 | * 135 | * @return string 136 | */ 137 | protected function getComposerJsonPath() 138 | { 139 | return base_path('composer.json'); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/Commands/Traits/CopiesSkeleton.php: -------------------------------------------------------------------------------- 1 | info('Copy skeleton.'); 38 | 39 | $skeletonDirPath = $this->getPathFromConfig( 40 | 'skeleton_dir_path', $this->packageBaseDir . '/skeleton' 41 | ); 42 | 43 | // this copies dirs which has files. We need to copy empty dirs too 44 | foreach (File::allFiles($skeletonDirPath, true) as $filePath) { 45 | $filePath = realpath($filePath); 46 | $destFilePath = Str::replaceFirst( 47 | $skeletonDirPath, $packagePath, $filePath 48 | ); 49 | 50 | $this->copyFileWithDirsCreating($filePath, $destFilePath); 51 | } 52 | 53 | 54 | $this->copyStubs($packagePath, $package, $packageFolderName); 55 | 56 | $variables = $this->getVariables( 57 | $vendor, $package, $vendorFolderName, $packageFolderName 58 | ); 59 | $this->replaceTemplates($packagePath, $variables); 60 | 61 | $this->info('Skeleton was successfully copied.'); 62 | } 63 | 64 | /** 65 | * Copy stubs. 66 | * 67 | * @param $packagePath 68 | * @param $package 69 | * @param $packageFolderName 70 | */ 71 | protected function copyStubs($packagePath, $package, $packageFolderName) 72 | { 73 | $facadeFilePath = $this->packageBaseDir . '/stubs/Facade.php.tpl'; 74 | $mainClassFilePath = $this->packageBaseDir . '/stubs/MainClass.php.tpl'; 75 | $mainClassTestFilePath = $this->packageBaseDir . '/stubs/MainClassTest.php.tpl'; 76 | $configFilePath = $this->packageBaseDir . '/stubs/config.php'; 77 | $routeFilePath = $this->packageBaseDir . '/stubs/routes.php.tpl'; 78 | 79 | $filePaths = [ 80 | $facadeFilePath => "$packagePath/src/Facades/$package.php.tpl", 81 | $mainClassFilePath => "$packagePath/src/$package.php.tpl", 82 | $routeFilePath => "$packagePath/src/routes.php.tpl", 83 | $mainClassTestFilePath => "$packagePath/tests/{$package}Test.php.tpl", 84 | $configFilePath => "$packagePath/config/$packageFolderName.php", 85 | ]; 86 | 87 | foreach ($filePaths as $filePath => $destFilePath) { 88 | $this->copyFileWithDirsCreating($filePath, $destFilePath); 89 | } 90 | 91 | foreach (config('wovosoft-crud.directories_to_create') as $directory_to_create) { 92 | if (!File::exists("$packagePath/$directory_to_create")) { 93 | if (!File::makeDirectory("$packagePath/$directory_to_create", 0755, true)) { 94 | throw new RuntimeException("Cannot create $directory_to_create folder"); 95 | } 96 | $this->info("$directory_to_create Folder Created"); 97 | } 98 | } 99 | 100 | } 101 | 102 | /** 103 | * Substitute all variables in *.tpl files and remove tpl extension. 104 | * 105 | * @param string $packagePath 106 | * @param array $variables 107 | */ 108 | protected function replaceTemplates($packagePath, $variables) 109 | { 110 | $phpEngine = app()->make(PhpEngine::class); 111 | 112 | foreach (File::allFiles($packagePath, true) as $filePath) { 113 | $filePath = realpath($filePath); 114 | 115 | if (!Str::endsWith($filePath, '.tpl')) { 116 | continue; 117 | } 118 | 119 | try { 120 | $newFileContent = $phpEngine->get($filePath, $variables); 121 | } catch (Exception $e) { 122 | $this->error("Template [$filePath] contains syntax errors"); 123 | $this->error($e->getMessage()); 124 | continue; 125 | } 126 | 127 | $filePathWithoutTplExt = Str::replaceLast( 128 | '.tpl', '', $filePath 129 | ); 130 | 131 | File::put($filePathWithoutTplExt, $newFileContent); 132 | File::delete($filePath); 133 | } 134 | } 135 | 136 | /** 137 | * Copy source file to destination with needed directories creating. 138 | * 139 | * @param string $src 140 | * @param string $dest 141 | */ 142 | protected function copyFileWithDirsCreating($src, $dest) 143 | { 144 | $dirPathOfDestFile = dirname($dest); 145 | 146 | if (!File::exists($dirPathOfDestFile)) { 147 | File::makeDirectory($dirPathOfDestFile, 0755, true); 148 | } 149 | 150 | if (!File::exists($dest)) { 151 | File::copy($src, $dest); 152 | } 153 | } 154 | 155 | /** 156 | * Get variables for substitution in templates. 157 | * 158 | * @param string $vendor 159 | * @param string $package 160 | * @param string $vendorFolderName 161 | * @param string $packageFolderName 162 | * 163 | * @return array 164 | */ 165 | protected function getVariables( 166 | $vendor, 167 | $package, 168 | $vendorFolderName, 169 | $packageFolderName 170 | ) 171 | { 172 | $packageWords = str_replace('-', ' ', Str::snake($packageFolderName)); 173 | 174 | $composerDescription = $this->askUser( 175 | 'The composer description?', "A $packageWords" 176 | ); 177 | $composerKeywords = $this->getComposerKeywords($packageWords); 178 | 179 | $packageHumanName = $this->askUser( 180 | 'The package human name?', Str::title($packageWords) 181 | ); 182 | 183 | return [ 184 | 'vendor' => $vendor, 185 | 'package' => $package, 186 | 'vendorFolderName' => $vendorFolderName, 187 | 'packageFolderName' => $packageFolderName, 188 | 'packageHumanName' => $packageHumanName, 189 | 190 | 'composerName' => "$vendorFolderName/$packageFolderName", 191 | 'composerDesc' => $composerDescription, 192 | 'composerKeywords' => $composerKeywords, 193 | 'license' => $this->askUser('The package licence?', 'MIT'), 194 | 'phpVersion' => $this->askUser('Php version constraint?', '>=7.2'), 195 | 196 | 'aliasName' => $packageFolderName, 197 | 'configFileName' => $packageFolderName, 198 | 199 | 'year' => date('Y'), 200 | 201 | 'name' => $this->askUser('Your name?'), 202 | 'email' => $this->askUser('Your email?'), 203 | 'githubPackageUrl' => "https://github.com/$vendorFolderName/$packageFolderName", 204 | ]; 205 | } 206 | 207 | /** 208 | * Get path from config. 209 | * 210 | * @param string $configName 211 | * @param string $default 212 | * 213 | * @return string 214 | * 215 | * @throws RuntimeException 216 | */ 217 | protected function getPathFromConfig($configName, $default) 218 | { 219 | $path = config("wovosoft-crud.$configName"); 220 | 221 | if (empty($path)) { 222 | $path = $default; 223 | } else { 224 | $path = base_path($path); 225 | } 226 | 227 | $realPath = realpath($path); 228 | 229 | if ($realPath === false) { 230 | throw RuntimeException::noAccessTo($path); 231 | } 232 | 233 | return $realPath; 234 | } 235 | 236 | /** 237 | * Get composer keywords. 238 | * 239 | * @param $packageWords 240 | * 241 | * @return string 242 | */ 243 | protected function getComposerKeywords($packageWords) 244 | { 245 | $keywords = $this->askUser( 246 | 'The composer keywords? (comma delimited)', str_replace(' ', ',', $packageWords) 247 | ); 248 | $keywords = explode(',', $keywords); 249 | $keywords = array_map(function ($keyword) { 250 | return "\"$keyword\""; 251 | }, $keywords); 252 | 253 | return implode(",\n" . str_repeat(' ', 4), $keywords); 254 | } 255 | } 256 | -------------------------------------------------------------------------------- /src/Commands/Traits/InteractsWithComposer.php: -------------------------------------------------------------------------------- 1 | composerRunCommand('composer dump-autoload'); 15 | } 16 | 17 | /** 18 | * Run "composer update $vendor/$package". 19 | * 20 | * @param string $vendor 21 | * @param string $package 22 | */ 23 | protected function composerUpdatePackage($vendor, $package) 24 | { 25 | $this->composerRunCommand("composer update --ignore-platform-reqs $vendor/$package"); 26 | } 27 | 28 | /** 29 | * Run "composer remove $vendor/$package". 30 | * 31 | * @param string $vendor 32 | * @param string $package 33 | */ 34 | protected function composerRemovePackage($vendor, $package) 35 | { 36 | $this->composerRunCommand("composer remove --ignore-platform-reqs $vendor/$package"); 37 | } 38 | 39 | /** 40 | * Run arbitrary composer command. 41 | * 42 | * @param $command 43 | */ 44 | protected function composerRunCommand($command) 45 | { 46 | $this->info("Run \"$command\"."); 47 | 48 | $output = []; 49 | exec($command, $output, $returnStatusCode); 50 | 51 | if ($returnStatusCode !== 0) { 52 | throw RuntimeException::commandExecutionFailed($command, $returnStatusCode); 53 | } 54 | 55 | $this->info("\"$command\" was successfully ran."); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Commands/Traits/InteractsWithGit.php: -------------------------------------------------------------------------------- 1 | info("Run \"$command\"."); 23 | 24 | File::makeDirectory($dest, 0755, true); 25 | 26 | $output = []; 27 | exec($command, $output, $returnStatusCode); 28 | 29 | if ($returnStatusCode !== 0) { 30 | throw RuntimeException::commandExecutionFailed( 31 | $command, $returnStatusCode 32 | ); 33 | } 34 | 35 | $this->info("\"$command\" was successfully ran."); 36 | } 37 | 38 | /** 39 | * Init git repo. 40 | * @param string $repoPath 41 | */ 42 | protected function initRepo($repoPath) 43 | { 44 | $command = "git init $repoPath"; 45 | $this->info("Run \"$command\"."); 46 | 47 | $output = []; 48 | exec($command, $output, $returnStatusCode); 49 | 50 | if ($returnStatusCode !== 0) { 51 | throw RuntimeException::commandExecutionFailed( 52 | $command, $returnStatusCode 53 | ); 54 | } 55 | 56 | $this->info("\"$command\" was successfully ran."); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Commands/Traits/InteractsWithUser.php: -------------------------------------------------------------------------------- 1 | argument('vendor') ?: $default; 19 | 20 | return $this->askUser('The vendor name?', $vendor); 21 | } 22 | 23 | /** 24 | * Get Model Name 25 | * @param string $default 26 | * @return string 27 | */ 28 | protected function getModel($default = '') 29 | { 30 | $vendor = $this->argument('model') ?: $default; 31 | 32 | return $this->askUser('The Model name?', $vendor); 33 | } 34 | 35 | /** 36 | * Getting Controller Name 37 | * @param string $default 38 | * @return string 39 | */ 40 | protected function getController($default = '') 41 | { 42 | $vendor = $this->argument('controller') ?: $default; 43 | 44 | return $this->askUser('The Controller name?', $vendor); 45 | } 46 | 47 | /** 48 | * Getting table name 49 | * @param string $default 50 | * @return string 51 | */ 52 | protected function getTable($default = '') 53 | { 54 | $vendor = $this->option('table') ?: $default; 55 | 56 | return $this->askUser('The Table name?', $vendor); 57 | } 58 | 59 | 60 | /** 61 | * Get the name of package for the namespace. 62 | * 63 | * @param string $default 64 | * 65 | * @return string 66 | */ 67 | protected function getPackage($default = '') 68 | { 69 | $package = $this->argument('package') ?: $default; 70 | 71 | return $this->askUser('The package name?', $package); 72 | } 73 | 74 | /** 75 | * Get vendor folder name. 76 | * 77 | * @param string $vendor 78 | * 79 | * @return string 80 | */ 81 | protected function getVendorFolderName($vendor) 82 | { 83 | $vendorFolderName = Str::kebab($vendor); 84 | 85 | return $this->askUser('The vendor folder name?', $vendorFolderName); 86 | } 87 | 88 | /** 89 | * Get package folder name. 90 | * 91 | * @param string $package 92 | * 93 | * @return string 94 | */ 95 | protected function getPackageFolderName($package) 96 | { 97 | $packageFolderName = Str::kebab($package); 98 | 99 | return $this->askUser('The package folder name?', $packageFolderName); 100 | } 101 | 102 | /** 103 | * Ask user. 104 | * 105 | * @param $question 106 | * @param $defaultValue 107 | * 108 | * @return string 109 | */ 110 | protected function askUser($question, $defaultValue = '') 111 | { 112 | if ($this->option('interactive') || $defaultValue == "") { 113 | return $this->ask($question, $defaultValue); 114 | } 115 | 116 | return trim($defaultValue); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/Commands/Traits/ManipulatesPackageFolder.php: -------------------------------------------------------------------------------- 1 | info('Create package folder.'); 20 | 21 | if (File::exists($packagePath)) { 22 | $this->info('Package folder already exists. Skipping.'); 23 | 24 | return; 25 | } 26 | 27 | if (! File::makeDirectory($packagePath, 0755, true)) { 28 | throw new RuntimeException('Cannot create package folder'); 29 | } 30 | 31 | $this->info('Package folder was successfully created.'); 32 | } 33 | 34 | /** 35 | * Remove package folder. 36 | * 37 | * @param $packagePath 38 | * 39 | * @throws RuntimeException 40 | */ 41 | protected function removePackageFolder($packagePath) 42 | { 43 | $this->info('Remove package folder.'); 44 | 45 | if (File::exists($packagePath)) { 46 | if (! File::deleteDirectory($packagePath)) { 47 | throw new RuntimeException('Cannot remove package folder'); 48 | } 49 | 50 | $this->info('Package folder was successfully removed.'); 51 | } else { 52 | $this->info('Package folder does not exists. Skipping.'); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Exceptions/RuntimeException.php: -------------------------------------------------------------------------------- 1 | publishes([ 20 | self::CONFIG_PATH => config_path('wovosoft-crud.php'), 21 | ], 'config'); 22 | 23 | if ($this->app->runningInConsole()) { 24 | $this->commands([ 25 | PackageNew::class, 26 | PackageRemove::class, 27 | MakeModel::class, 28 | RemoveModel::class, 29 | MakeController::class, 30 | RemoveController::class, 31 | CrudCommand::class 32 | ]); 33 | } 34 | } 35 | 36 | public function register() 37 | { 38 | $this->mergeConfigFrom( 39 | self::CONFIG_PATH, 40 | 'wovosoft-crud' 41 | ); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /stubs/Controller.php.tpl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace \\Http\Controllers; 5 | 6 | use App\Http\Controllers\Controller; 7 | 8 | use Bornodhoni\CMSBase\Traits\BaseControllerTrait; 9 | use Illuminate\Http\Request; 10 | use Illuminate\Support\Carbon; 11 | use Illuminate\Support\Facades\Route; 12 | use Symfony\Component\HttpFoundation\Response; 13 | use as ItemModel; 14 | 15 | class extends Controller 16 | { 17 | use BaseControllerTrait; 18 | public $itemModel; 19 | /** 20 | * @var array List of Relations to be loaded with the list() method 21 | */ 22 | public $listWith = [ 23 | 24 | ]; 25 | /** 26 | * @var array List of Columns to be selected with the list() method 27 | */ 28 | public $listSelectedColumns = [ 29 | "*" 30 | ]; 31 | 32 | public function __construct() 33 | { 34 | $this->itemModel = ItemModel::class; 35 | } 36 | 37 | public static function routes() 38 | { 39 | Route::post("/list", '\\' . __CLASS__ . '@list')->name('.List'); 40 | Route::post("/search", '\\' . __CLASS__ . '@search')->name('.Search'); 41 | Route::post("/store", '\\' . __CLASS__ . '@store')->name('.Store'); 42 | Route::post("/delete", '\\' . __CLASS__ . '@delete')->name('.Delete'); 43 | } 44 | 45 | public function store(Request $request) 46 | { 47 | try { 48 | $item = ItemModel::findOrNew($request->post('id')); 49 | if ($request->post('id')) { 50 | $item->updated_at = Carbon::now(); 51 | } 52 | $item->saveOrFail(); 53 | return response()->json([ 54 | "status" => true, 55 | "title" => 'SUCCESS!', 56 | "type" => "success", 57 | "msg" => ($request->post('id') ? 'Edited' : 'Added') . ' Successfully' 58 | ]); 59 | } catch (\Exception $exception) { 60 | if(env('APP_DEBUG')){ 61 | return response()->json([ 62 | "code" => $exception->getCode(), 63 | "status" => false, 64 | "title" => 'Failed!', 65 | "type" => "warning", 66 | "msg" => $exception->getMessage(), 67 | "line" => $exception->getLine(), 68 | "file" => $exception->getFile(), 69 | "trace" => $exception->getTrace(), 70 | ], Response::HTTP_FORBIDDEN, [], JSON_PRETTY_PRINT); 71 | } 72 | return response()->json([ 73 | "status" => false, 74 | "title" => 'Failed!', 75 | "type" => "warning", 76 | "msg" => "Unable to Process the request" 77 | ], Response::HTTP_FORBIDDEN); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /stubs/Facade.php.tpl: -------------------------------------------------------------------------------- 1 | 2 | 3 | namespace \\Facades; 4 | 5 | use Illuminate\Support\Facades\Facade; 6 | 7 | class extends Facade 8 | { 9 | protected static function getFacadeAccessor() 10 | { 11 | return ''; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /stubs/MainClass.php.tpl: -------------------------------------------------------------------------------- 1 | 2 | 3 | namespace \; 4 | 5 | class 6 | { 7 | } 8 | -------------------------------------------------------------------------------- /stubs/MainClassTest.php.tpl: -------------------------------------------------------------------------------- 1 | 2 | 3 | namespace \\Tests; 4 | 5 | use \\Facades\; 6 | use \\ServiceProvider; 7 | use Orchestra\Testbench\TestCase; 8 | 9 | class Test extends TestCase 10 | { 11 | protected function getPackageProviders($app) 12 | { 13 | return [ServiceProvider::class]; 14 | } 15 | 16 | protected function getPackageAliases($app) 17 | { 18 | return [ 19 | '' => ::class, 20 | ]; 21 | } 22 | 23 | public function testExample() 24 | { 25 | $this->assertEquals(1, 1); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /stubs/Model.php.tpl: -------------------------------------------------------------------------------- 1 | 2 | 3 | namespace \\Models; 4 | 5 | use Illuminate\Database\Eloquent\Model; 6 | 7 | class extends Model 8 | { 9 | protected $table = ""; 10 | //protected $fillable = []; 11 | 12 | 13 | } 14 | -------------------------------------------------------------------------------- /stubs/config.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | use Illuminate\Support\Facades\Route; 4 | //MAPPING_AREA_FOR_CRUD_DO_NOT_REMOVE_OR_EDIT_THIS_LINE_USE_AREA// 5 | 6 | 7 | Route::name('.') 8 | ->prefix('backend') 9 | ->middleware(['web', 'auth']) 10 | ->group(function () { 11 | 12 | //MAPPING_AREA_FOR_CRUD_DO_NOT_REMOVE_OR_EDIT_THIS_LINE// 13 | }); 14 | -------------------------------------------------------------------------------- /stubs/seeder.stub: -------------------------------------------------------------------------------- 1 |