├── .editorconfig ├── .scrutinizer.yml ├── .styleci.yml ├── .travis.yml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md ├── LICENSE.md ├── PULL_REQUEST_TEMPLATE.md ├── README.md ├── composer.json ├── config └── generators.php ├── phpunit.xml ├── src ├── Commands │ └── MakeEntity.php ├── Contracts │ ├── CommandAbstract.php │ ├── NamingAbstract.php │ ├── OpenInIdeAbstract.php │ ├── OpenInIdeInterface.php │ ├── SchemaFieldAbstract.php │ ├── SchemaFieldTypeInterface.php │ ├── ServiceAbstract.php │ └── ServiceInterface.php ├── GeneratorsServiceProvider.php ├── Helper │ ├── RegexParser.php │ └── ShortSyntaxArray.php ├── Recipes │ ├── PhpStormOpener.php │ ├── SublimeOpener.php │ └── VSCodeOpener.php ├── Schemas │ ├── FieldTypes │ │ ├── DateType.php │ │ ├── NumberType.php │ │ ├── StringType.php │ │ ├── SummernoteType.php │ │ └── TextType.php │ ├── Naming │ │ ├── CrudController.php │ │ ├── CrudModel.php │ │ ├── CrudRequest.php │ │ ├── Factory.php │ │ ├── LanguageFile.php │ │ ├── Migration.php │ │ ├── RouteFile.php │ │ ├── Seeder.php │ │ └── Sidebar.php │ └── Schema.php ├── Services │ ├── AddToGitService.php │ ├── BackpackCrudControllerService.php │ ├── BackpackCrudModelService.php │ ├── BackpackCrudRequestService.php │ ├── FactoryService.php │ ├── LanguageFileService.php │ ├── MigrationService.php │ ├── OpenIdeService.php │ ├── RouteService.php │ ├── SeederService.php │ └── SidebarService.php └── Traits │ ├── CanGenerateFile.php │ ├── CrudColumn.php │ ├── CrudField.php │ ├── MigrationField.php │ └── ValidationRule.php └── stubs ├── crud-controller.stub ├── crud-model.stub ├── crud-request.stub ├── factory.stub ├── migration.stub └── seeder.stub /.editorconfig: -------------------------------------------------------------------------------- 1 | ; This file is for unifying the coding style for different editors and IDEs. 2 | ; More information at http://editorconfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | charset = utf-8 8 | indent_size = 4 9 | indent_style = space 10 | end_of_line = lf 11 | insert_final_newline = true 12 | trim_trailing_whitespace = true 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /.scrutinizer.yml: -------------------------------------------------------------------------------- 1 | filter: 2 | paths: 3 | - 'app/*' 4 | - 'src/*' 5 | excluded_paths: 6 | - 'bootstrap/*' 7 | - 'config/*' 8 | - 'public/*' 9 | - 'resources/*' 10 | - 'vendor/*' 11 | - 'views/*' 12 | tools: 13 | php_analyzer: true 14 | php_mess_detector: true 15 | php_changetracking: true 16 | php_code_sniffer: 17 | config: 18 | standard: PSR2 19 | php_loc: 20 | excluded_dirs: 21 | - vendor 22 | php_pdepend: 23 | excluded_dirs: 24 | - vendor 25 | - tests 26 | build: 27 | tests: 28 | before: 29 | - 'composer self-update' 30 | - 'composer update --no-interaction --prefer-source' 31 | override: 32 | - 33 | command: 'vendor/bin/phpunit --coverage-clover coverage.clover' 34 | coverage: 35 | file: 'coverage.clover' 36 | format: 'clover' 37 | checks: 38 | php: 39 | code_rating: true 40 | duplication: true 41 | variable_existence: true 42 | useless_calls: true 43 | use_statement_alias_conflict: true 44 | unused_variables: true 45 | unused_properties: true 46 | unused_parameters: true 47 | unused_methods: true 48 | unreachable_code: true 49 | sql_injection_vulnerabilities: true 50 | security_vulnerabilities: true 51 | precedence_mistakes: true 52 | precedence_in_conditions: true 53 | parameter_non_unique: true 54 | no_property_on_interface: true 55 | no_non_implemented_abstract_methods: true 56 | deprecated_code_usage: true 57 | closure_use_not_conflicting: true 58 | closure_use_modifiable: true 59 | avoid_useless_overridden_methods: true 60 | avoid_conflicting_incrementers: true 61 | assignment_of_null_return: true 62 | verify_property_names: true 63 | verify_argument_usable_as_reference: true 64 | verify_access_scope_valid: true 65 | use_self_instead_of_fqcn: true 66 | too_many_arguments: true 67 | symfony_request_injection: true 68 | switch_fallthrough_commented: true 69 | spacing_of_function_arguments: true 70 | spacing_around_non_conditional_operators: true 71 | spacing_around_conditional_operators: true 72 | space_after_cast: true 73 | single_namespace_per_use: true 74 | simplify_boolean_return: true 75 | scope_indentation: 76 | spaces_per_level: '4' 77 | return_doc_comments: true 78 | require_scope_for_properties: true 79 | require_scope_for_methods: true 80 | require_php_tag_first: true 81 | require_braces_around_control_structures: true 82 | remove_trailing_whitespace: true 83 | remove_php_closing_tag: true 84 | remove_extra_empty_lines: true 85 | psr2_switch_declaration: true 86 | psr2_control_structure_declaration: true 87 | psr2_class_declaration: true 88 | property_assignments: true 89 | properties_in_camelcaps: true 90 | prefer_while_loop_over_for_loop: true 91 | phpunit_assertions: true 92 | php5_style_constructor: true 93 | parameters_in_camelcaps: true 94 | parameter_doc_comments: true 95 | return_doc_comment_if_not_inferrable: true 96 | param_doc_comment_if_not_inferrable: true 97 | overriding_private_members: true 98 | optional_parameters_at_the_end: true 99 | one_class_per_file: true 100 | non_commented_empty_catch_block: true 101 | no_unnecessary_if: true 102 | no_unnecessary_function_call_in_for_loop: true 103 | no_unnecessary_final_modifier: true 104 | no_underscore_prefix_in_properties: true 105 | no_underscore_prefix_in_methods: true 106 | no_trailing_whitespace: true 107 | no_space_inside_cast_operator: true 108 | no_space_before_semicolon: true 109 | no_space_around_object_operator: true 110 | no_goto: true 111 | no_global_keyword: true 112 | no_exit: true 113 | no_empty_statements: true 114 | no_else_if_statements: true 115 | no_duplicate_arguments: true 116 | no_debug_code: true 117 | no_commented_out_code: true 118 | newline_at_end_of_file: true 119 | naming_conventions: 120 | local_variable: '^[a-z][a-zA-Z0-9]*$' 121 | abstract_class_name: ^Abstract|Factory$ 122 | utility_class_name: 'Utils?$' 123 | constant_name: '^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$' 124 | property_name: '^[a-z][a-zA-Z0-9]*$' 125 | method_name: '^(?:[a-z]|__)[a-zA-Z0-9]*$' 126 | parameter_name: '^[a-z][a-zA-Z0-9]*$' 127 | interface_name: '^[A-Z][a-zA-Z0-9]*Interface$' 128 | type_name: '^[A-Z][a-zA-Z0-9]*$' 129 | exception_name: '^[A-Z][a-zA-Z0-9]*Exception$' 130 | isser_method_name: '^(?:is|has|should|may|supports|was)' 131 | lowercase_php_keywords: true 132 | more_specific_types_in_doc_comments: true 133 | missing_arguments: true 134 | method_calls_on_non_object: true 135 | line_length: 136 | max_length: '120' 137 | lowercase_basic_constants: true 138 | instanceof_class_exists: true 139 | function_in_camel_caps: true 140 | function_body_start_on_new_line: true 141 | fix_use_statements: 142 | remove_unused: true 143 | preserve_multiple: false 144 | preserve_blanklines: false 145 | order_alphabetically: true 146 | foreach_traversable: true 147 | foreach_usable_as_reference: true 148 | fix_php_opening_tag: true 149 | fix_line_ending: true 150 | fix_identation_4spaces: true 151 | fix_doc_comments: true 152 | ensure_lower_case_builtin_functions: true 153 | encourage_postdec_operator: true 154 | classes_in_camel_caps: true 155 | catch_class_exists: true 156 | blank_line_after_namespace_declaration: true 157 | avoid_usage_of_logical_operators: true 158 | avoid_unnecessary_concatenation: true 159 | avoid_tab_indentation: true 160 | avoid_superglobals: true 161 | avoid_perl_style_comments: true 162 | avoid_multiple_statements_on_same_line: true 163 | avoid_fixme_comments: true 164 | avoid_length_functions_in_loops: true 165 | avoid_entity_manager_injection: true 166 | avoid_duplicate_types: true 167 | avoid_corrupting_byteorder_marks: true 168 | argument_type_checks: true 169 | avoid_aliased_php_functions: true 170 | deadlock_detection_in_loops: true -------------------------------------------------------------------------------- /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: psr2 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 7.1 5 | - nightly 6 | 7 | matrix: 8 | allow_failures: 9 | - php: nightly 10 | 11 | env: 12 | matrix: 13 | - COMPOSER_FLAGS="--prefer-lowest" 14 | - COMPOSER_FLAGS="" 15 | 16 | before_script: 17 | - travis_retry composer self-update 18 | - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source 19 | 20 | script: 21 | - vendor/bin/phpunit --coverage-clover coverage.clover 22 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `laravel-generators` will be documented in this file. 4 | 5 | Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles. 6 | 7 | ## NEXT - YYYY-MM-DD 8 | 9 | ### Added 10 | - Nothing 11 | 12 | ### Deprecated 13 | - Nothing 14 | 15 | ### Fixed 16 | - Nothing 17 | 18 | ### Removed 19 | - Nothing 20 | 21 | ### Security 22 | - Nothing 23 | 24 | ## 3.3.3 - 2018-03-16 25 | 26 | ### Added 27 | 28 | - support for Laravel 5.8 29 | 30 | ## 3.3.0 - 2018-11-16 31 | 32 | ### Added 33 | 34 | - add setRequiredFields() by default 35 | 36 | ## 3.2.0 - 2018-11-11 37 | 38 | ### Added 39 | 40 | - use "open in IDE" also via `config` or `.env` - see README for details 41 | - strip spaces from schema-string 42 | 43 | ### Changed 44 | 45 | - output naming classes only with -v (verbose) option 46 | 47 | ## 3.1.0 - 2018-06-25 48 | 49 | ### Added 50 | 51 | - Opener classes for Sublime and VS Code 52 | 53 | ## 3.0.0 - 2018-06-24 - Complete Refactoring 54 | 55 | The Refactoring is supposed to provide new functions more easily in the future. 56 | 57 | Attention: `schema` has been changed and only registered FieldTypes (see config-file) will be parsed. There are only a few FieldTypes available at the moment, more will come soon. 58 | 59 | ### Added 60 | 61 | - `AddToGitService`: using `--git` in command will add all files to git 62 | 63 | ### Changed 64 | 65 | - The parsing of `--schema=""` is now a bit different, but much more powerful. Please see Readme for further information 66 | - Naming for each service is handled by dedicated classes and can be accessed everywhere (e.g. name of Model inside a CrudController) 67 | 68 | ### Removed 69 | 70 | - additional commands which are now integrated in the corresponding services 71 | 72 | ## 2.1.0 - 2018-03-30 (for Backpack Base v0.9) 73 | 74 | ### Added 75 | - `SidebarService` adds an entry to your sidebar 76 | 77 | ### Changed 78 | - `RouteService` now uses `routes/backpack/custom.php 79 | 80 | ## 2.0.0 - 2018-03-23 81 | 82 | ### Added 83 | - `LanguageFileService` generates models.php translation file (if not exists) and fill singular/plural translation 84 | - `OpenIdeService` opens all generated file with PhpStorm if command is called with `--ide={ide}` 85 | - `RouteService` adds Backpack Crud route to admin.php 86 | 87 | ### Changed 88 | 89 | - `BackpackCrudModelService` will fill `$fillable` in Model automatically from scheme (if given) 90 | - `BackpackCrudRequestService` will fill `rules()` in Request automatically from scheme (if given) 91 | - `BackpackCrudControllerService` will add CrudFields and CrudColumns in Controller automatically from scheme (if given) - very rudimentary for now, more functionality planned 92 | 93 | ## 1.2.0 - 2018-03-18 94 | 95 | ### Added 96 | - integrate backpack crud commands and stubs 97 | 98 | ## 1.1.1 - 2018-03-17 99 | 100 | ### Fixed 101 | - function calls for conversion names 102 | 103 | ## 1.1.0 - 2018-03-17 104 | 105 | ### Added 106 | - --schema option for migrations 107 | 108 | ## 1.0.0 - 2018-03-16 109 | 110 | ### Added 111 | - initial Version 112 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to make participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at `oliver.ziegler@webfactor.de`. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ 75 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | We accept contributions via Pull Requests on [Github](https://github.com/webfactor/laravel-openinghours). 6 | 7 | 8 | ## Pull Requests 9 | 10 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - Check the code style with ``$ composer check-style`` and fix it with ``$ composer fix-style``. 11 | 12 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 13 | 14 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 15 | 16 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. 17 | 18 | - **Create feature branches** - Don't ask us to pull from your master branch. 19 | 20 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 21 | 22 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 23 | 24 | 25 | ## Running Tests 26 | 27 | ``` bash 28 | $ composer test 29 | ``` 30 | 31 | 32 | **Happy coding**! 33 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Detailed description 4 | 5 | Provide a detailed description of the change or addition you are proposing. 6 | 7 | Make it clear if the issue is a bug, an enhancement or just a question. 8 | 9 | ## Context 10 | 11 | Why is this change important to you? How would you use it? 12 | 13 | How can it benefit other users? 14 | 15 | ## Possible implementation 16 | 17 | Not obligatory, but suggest an idea for implementing addition or change. 18 | 19 | ## Your environment 20 | 21 | Include as many relevant details about the environment you experienced the bug in and how to reproduce it. 22 | 23 | * Version used (e.g. PHP 5.6, HHVM 3): 24 | * Operating system and version (e.g. Ubuntu 16.04, Windows 7): 25 | * Link to your project: 26 | * ... 27 | * ... 28 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) 2018 webfactor media GmbH 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 | -------------------------------------------------------------------------------- /PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Description 4 | 5 | Describe your changes in detail. 6 | 7 | ## Motivation and context 8 | 9 | Why is this change required? What problem does it solve? 10 | 11 | If it fixes an open issue, please link to the issue here (if you write `fixes #num` 12 | or `closes #num`, the issue will be automatically closed when the pull is accepted.) 13 | 14 | ## How has this been tested? 15 | 16 | Please describe in detail how you tested your changes. 17 | 18 | Include details of your testing environment, and the tests you ran to 19 | see how your change affects other areas of the code, etc. 20 | 21 | ## Screenshots (if appropriate) 22 | 23 | ## Types of changes 24 | 25 | What types of changes does your code introduce? Put an `x` in all the boxes that apply: 26 | - [ ] Bug fix (non-breaking change which fixes an issue) 27 | - [ ] New feature (non-breaking change which adds functionality) 28 | - [ ] Breaking change (fix or feature that would cause existing functionality to change) 29 | 30 | ## Checklist: 31 | 32 | Go over all the following points, and put an `x` in all the boxes that apply. 33 | 34 | Please, please, please, don't send your pull request until all of the boxes are ticked. Once your pull request is created, it will trigger a build on our [continuous integration](http://www.phptherightway.com/#continuous-integration) server to make sure your [tests and code style pass](https://help.github.com/articles/about-required-status-checks/). 35 | 36 | - [ ] I have read the **[CONTRIBUTING](CONTRIBUTING.md)** document. 37 | - [ ] My pull request addresses exactly one patch/feature. 38 | - [ ] I have created a branch for this patch/feature. 39 | - [ ] Each individual commit in the pull request is meaningful. 40 | - [ ] I have added tests to cover my changes. 41 | - [ ] If my change requires a change to the documentation, I have updated it accordingly. 42 | 43 | If you're unsure about any of these, don't hesitate to ask. We're here to help! 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # laravel-generators 2 | 3 | [![Latest Version on Packagist][ico-version]][link-packagist] 4 | [![Software License][ico-license]](LICENSE.md) 5 | [![StyleCI][ico-style-ci]][link-style-ci] 6 | [![Build Status][ico-travis]][link-travis] 7 | [![Coverage Status][ico-scrutinizer]][link-scrutinizer] 8 | [![Quality Score][ico-code-quality]][link-code-quality] 9 | [![Total Downloads][ico-downloads]][link-downloads] 10 | 11 | This is a package developed by us for internal use. It is supposed to help us during development and save plenty of time by automating many steps while creating typical CRUD entities with [Laravel Backpack](https://laravel-backpack.readme.io/docs). You can write your own Services (they have to implement `Webfactor\Laravel\Generators\Contracts\ServiceInterface`) and register them in the `generators.php` config file, or use this package as an inspiration for your own implementation. 12 | 13 | ## Install 14 | 15 | ### Via Composer 16 | 17 | This package is indended to be used only for development, not for production. Because of that we recommend to use `require-dev`: 18 | 19 | ``` bash 20 | composer require --dev webfactor/laravel-generators 21 | ``` 22 | 23 | ## Usage 24 | 25 | ``` bash 26 | php artisan make:entity {entity_name} {--schema=} {--migrate} {--ide=} {--git} 27 | ``` 28 | 29 | - `entity_name`: Recommendation: use *singular* for entity. see "[Naming](#naming)" for more information 30 | - `--schema=`: Here you can provide a [schema-String](#schema) 31 | - `--migrate`: will automatically call `php artisan migrate` after creating the migration file 32 | - `--ide=`: will open all files in your prefered [IDE](#open-files-in-ide) 33 | - `--git`: will add all files to [git](#add-files-to-git) 34 | 35 | 36 | If you want to add Services, Naming classes, Field Types, or IDE Opener you have to publish the config-file: 37 | 38 | ``` bash 39 | php artisan vendor:publish --provider="Webfactor\Laravel\Generators\GeneratorsServiceProvider" 40 | ``` 41 | 42 | ## Services 43 | 44 | All Services defined in the config file have to implement `Webfactor\Laravel\Generators\Contracts\ServiceInterface` and will then be called in the given order. 45 | 46 | ### Included Services 47 | 48 | Can be removed or extended by publishing config file: 49 | 50 | - `MigrationService` 51 | - `FactoryService` 52 | - `SeederService` 53 | - Backpack CRUD: 54 | - `BackpackCrudModelService` (incl. `$fillable`) 55 | - `BackpackCrudRequestService` (incl. `rules()`) 56 | - `BackpackCrudControllerService` (incl. CrudColumns and CrudFields, more coming soon) 57 | - `SidebarService` 58 | - `LanguageFileService` 59 | - `RouteFileService` 60 | 61 | ### Always available (activated by option): 62 | 63 | - `OpenIdeService` 64 | - `AddToGitService` 65 | 66 | ## Schema 67 | 68 | The intention of this package concerning Laravel Backpack CRUD is to provide an easy way to define standard Field Types with some default options and override them if necessary. 69 | 70 | Example: 71 | 72 | ``` bash 73 | php artisan make:entity blog --schema="title:string,text:summernote" 74 | ``` 75 | 76 | This will use the `StringType` and `SummernoteType` classes to create (besides all other files): 77 | 78 | - Blog.php with `$fillable = ['title', 'text']` 79 | - BlogRequest.php with predefined rules for each field 80 | - BlogCrudController.php with columns and fields for `title` and `text` 81 | 82 | If you want to add/overwrite certain options you can use something like this: 83 | 84 | ``` bash 85 | php artisan make:entity blog --schema="title:string(unique|default:title);rule(required|min:3|max:64),text:summernote;field(label:Content);column(label:Content)" 86 | ``` 87 | 88 | ## Field Types 89 | 90 | Currently available Field Types (more coming soon): 91 | 92 | - Date 93 | - Number 94 | - String 95 | - Summernote (as a proof of concept) 96 | - Text 97 | 98 | The available definitions in the Field Type classes currently are: 99 | 100 | ```php 101 | public $validationRule; // 'required|min:5'... 102 | 103 | public $migrationField = [ 104 | 'type' => 'string', // any type available for a migration file 105 | // optional: 106 | // 'unique' => true 107 | // 'default' => 'value' 108 | // 'nullable' => true 109 | // etc. 110 | ]; 111 | 112 | public $crudColumn = [ 113 | 'type' => 'text', // or date, number, any backpack column 114 | // 'label' => 'Name of label' 115 | // ... any option 116 | ]; 117 | 118 | public $crudField = [ 119 | 'type' => 'text', // or date, number, any backpack field 120 | // 'label' => 'Name of label' 121 | // ... prefix, suffix... any option 122 | ]; 123 | ``` 124 | 125 | ## Naming 126 | 127 | You can provide your own naming convention classes by registering them in the config file. This classes should extend `Webfactor\Laravel\Generators\Contracts\NamingAbstract` to provide a certain base functionality. 128 | 129 | Example for `Webfactor\Laravel\Generators\Schemas\Naming\CrudController`: 130 | 131 | ```php 132 | getAppNamespace() . 'Http\\Controllers\\Admin'; 146 | } 147 | 148 | /** 149 | * @return string 150 | */ 151 | public function getClassName(): string 152 | { 153 | return ucfirst($this->entity) . 'CrudController'; 154 | } 155 | 156 | /** 157 | * @return string 158 | */ 159 | public function getFileName(): string 160 | { 161 | return $this->getClassName() . '.php'; 162 | } 163 | 164 | /** 165 | * @return string 166 | */ 167 | public function getPath(): string 168 | { 169 | return app_path('Http/Controllers/Admin'); 170 | } 171 | 172 | /** 173 | * @return string 174 | */ 175 | public function getStub(): string 176 | { 177 | return __DIR__ . '/../../../stubs/crud-controller.stub'; 178 | } 179 | } 180 | ``` 181 | 182 | All naming classes defined in the config file will be parsed and saved with their keys to the `$naming`-array of the command. As the entire command is available in each service class, you can access ALL naming conventions everywhere! 183 | 184 | For example you need the `Request`-namespace in the CrudController: `$this->command->naming['crudRequest']->getNamespace()`. 185 | 186 | Furthermore there is a helper to keep things a bit simpler if you are IN the service class of the coresponding naming class! Just define `$key` and you can access the naming conventions directly through `$this->naming`: 187 | 188 | ```php 189 | naming; 200 | // same to 201 | echo $this->command->naming['myNaming']; 202 | // but you can additionally access 203 | echo $this->command->naming['otherNaming']; 204 | } 205 | } 206 | ``` 207 | 208 | ## Add files to git 209 | 210 | With `{--git}` option all generated files will be added to git automatically. In your service class you have to add the generated file. You can: 211 | 212 | - use `$this->command->addFile(SplileInfo $file)` or 213 | - use `$this->addGeneratedFileToIdeStack()` if you use a naming key or 214 | - use the `Webfactor\Laravel\Generators\Traits\CanGenerateFile` define a naming key and just implement a `buildFileContent()` method 215 | 216 | ## Open files in IDE 217 | 218 | If specified we will automatically open all generated files in the IDE of your choice. 219 | There are three options to use this feature (applied in this order): 220 | * `{--ide=}` command option 221 | * __.env__ variable `APP_EDITOR` 222 | * config value `config('app.editor')` 223 | 224 | The keys in the `ides`-Array of the config file are possible values for the command option. 225 | Per default we provide: 226 | * `phpstorm`: will open all files with `pstorm` CLI helper of PhpStorm 227 | * `pstorm`: will open all files with `pstorm` CLI helper of PhpStorm 228 | * `sublime`: will open all files with `subl` CLI helper of Sublime 229 | * `subl`: will open all files with `subl` CLI helper of Sublime 230 | * `vscode`: will open all files with `code` CLI helper of VSCode 231 | * `code`: will open all files with `code` CLI helper of VSCode 232 | 233 | You can add other IDE-Opener classes. They have to implement `Webfactor\Laravel\Generators\Contracts\OpenInIdeInterface`. 234 | 235 | In your service class you have to add the generated file to a stack (see "Add files to git" section) 236 | 237 | 238 | ## Adaption 239 | 240 | Feel free to write your own Services that fit your purposes! 241 | 242 | ## Change log 243 | 244 | Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. 245 | 246 | ## Contributing 247 | 248 | Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) for details. 249 | 250 | ## Security 251 | 252 | If you discover any security related issues, please email thomas.swonke@webfactor.de instead of using the issue tracker. 253 | 254 | ## Credits 255 | 256 | - [Thomas Swonke][link-author] 257 | - [Oliver Ziegler](https://github.com/OliverZiegler) 258 | - [Cristian Tabacitu](https://github.com/tabacitu) 259 | - [All Contributors][link-contributors] 260 | 261 | ## License 262 | 263 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 264 | 265 | [ico-version]: https://img.shields.io/packagist/v/webfactor/laravel-generators.svg?style=flat-square 266 | [ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square 267 | [ico-style-ci]: https://styleci.io/repos/125574603/shield 268 | [ico-travis]: https://img.shields.io/travis/webfactor/laravel-generators/master.svg?style=flat-square 269 | [ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/webfactor/laravel-generators.svg?style=flat-square 270 | [ico-code-quality]: https://img.shields.io/scrutinizer/g/webfactor/laravel-generators.svg?style=flat-square 271 | [ico-downloads]: https://img.shields.io/packagist/dt/webfactor/laravel-generators.svg?style=flat-square 272 | 273 | [link-packagist]: https://packagist.org/packages/webfactor/laravel-generators 274 | [link-style-ci]: https://styleci.io/repos/125574603 275 | [link-travis]: https://travis-ci.org/webfactor/laravel-generators 276 | [link-scrutinizer]: https://scrutinizer-ci.com/g/webfactor/laravel-generators/code-structure 277 | [link-code-quality]: https://scrutinizer-ci.com/g/webfactor/laravel-generators 278 | [link-downloads]: https://packagist.org/packages/webfactor/laravel-generators 279 | [link-author]: https://github.com/tswonke 280 | [link-contributors]: ../../contributors 281 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webfactor/laravel-generators", 3 | "type": "library", 4 | "description": "Laravel generators for quickly creating entities.", 5 | "keywords": [ 6 | "webfactor", 7 | "laravel", 8 | "backpack", 9 | "generators" 10 | ], 11 | "homepage": "https://github.com/webfactor/laravel-generators", 12 | "license": "MIT", 13 | "authors": [ 14 | { 15 | "name": "Thomas Swonke", 16 | "email": "thomas.swonke@webfactor.de", 17 | "homepage": "http://webfactor.de", 18 | "role": "Developer" 19 | }, 20 | { 21 | "name": "Oliver Ziegler", 22 | "email": "oliver.ziegler@webfactor.de", 23 | "homepage": "http://webfactor.de", 24 | "role": "Developer" 25 | } 26 | ], 27 | "require": { 28 | "illuminate/support": "~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0", 29 | "illuminate/database": "~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0", 30 | "php": "~7.1" 31 | }, 32 | "require-dev": { 33 | "phpunit/phpunit": "~6.0", 34 | "squizlabs/php_codesniffer": "^2.3" 35 | }, 36 | "autoload": { 37 | "psr-4": { 38 | "Webfactor\\Laravel\\Generators\\": "src" 39 | } 40 | }, 41 | "autoload-dev": { 42 | "psr-4": { 43 | } 44 | }, 45 | "scripts": { 46 | "test": "phpunit", 47 | "check-style": "phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests", 48 | "fix-style": "phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests" 49 | }, 50 | "extra": { 51 | "laravel": { 52 | "providers": [ 53 | "Webfactor\\Laravel\\Generators\\GeneratorsServiceProvider" 54 | ] 55 | }, 56 | "branch-alias": { 57 | "dev-master": "3.0.x-dev" 58 | } 59 | }, 60 | "config": { 61 | "sort-packages": true 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /config/generators.php: -------------------------------------------------------------------------------- 1 | [ 9 | Webfactor\Laravel\Generators\Services\MigrationService::class, 10 | Webfactor\Laravel\Generators\Services\LanguageFileService::class, 11 | Webfactor\Laravel\Generators\Services\BackpackCrudModelService::class, 12 | Webfactor\Laravel\Generators\Services\BackpackCrudRequestService::class, 13 | Webfactor\Laravel\Generators\Services\BackpackCrudControllerService::class, 14 | Webfactor\Laravel\Generators\Services\FactoryService::class, 15 | Webfactor\Laravel\Generators\Services\SeederService::class, 16 | Webfactor\Laravel\Generators\Services\RouteService::class, 17 | Webfactor\Laravel\Generators\Services\SidebarService::class, 18 | ], 19 | 20 | /* 21 | * Recipe classes for opening all generated files directly in IDE if the option --ide={key} 22 | * is used. Have to implement Webfactor\Laravel\Generators\Contracts\OpenIdeInterface. 23 | */ 24 | 'ides' => [ 25 | 'phpstorm' => Webfactor\Laravel\Generators\Recipes\PhpStormOpener::class, 26 | 'pstorm' => Webfactor\Laravel\Generators\Recipes\PhpStormOpener::class, 27 | 'sublime' => Webfactor\Laravel\Generators\Recipes\SublimeOpener::class, 28 | 'subl' => Webfactor\Laravel\Generators\Recipes\SublimeOpener::class, 29 | 'vscode' => Webfactor\Laravel\Generators\Recipes\VSCodeOpener::class, 30 | 'code' => Webfactor\Laravel\Generators\Recipes\VSCodeOpener::class, 31 | ], 32 | 33 | 'naming' => [ 34 | 'migration' => Webfactor\Laravel\Generators\Schemas\Naming\Migration::class, 35 | 'languageFile' => Webfactor\Laravel\Generators\Schemas\Naming\LanguageFile::class, 36 | 'crudModel' => Webfactor\Laravel\Generators\Schemas\Naming\CrudModel::class, 37 | 'crudRequest' => Webfactor\Laravel\Generators\Schemas\Naming\CrudRequest::class, 38 | 'crudController' => Webfactor\Laravel\Generators\Schemas\Naming\CrudController::class, 39 | 'routeFile' => Webfactor\Laravel\Generators\Schemas\Naming\RouteFile::class, 40 | 'factory' => Webfactor\Laravel\Generators\Schemas\Naming\Factory::class, 41 | 'seeder' => Webfactor\Laravel\Generators\Schemas\Naming\Seeder::class, 42 | 'sidebar' => Webfactor\Laravel\Generators\Schemas\Naming\Sidebar::class, 43 | ], 44 | 45 | 'fieldTypes' => [ 46 | 'date' => \Webfactor\Laravel\Generators\Schemas\FieldTypes\DateType::class, 47 | 'number' => \Webfactor\Laravel\Generators\Schemas\FieldTypes\NumberType::class, 48 | 'summernote' => \Webfactor\Laravel\Generators\Schemas\FieldTypes\SummernoteType::class, 49 | 'string' => \Webfactor\Laravel\Generators\Schemas\FieldTypes\StringType::class, 50 | 'text' => \Webfactor\Laravel\Generators\Schemas\FieldTypes\TextType::class, 51 | ], 52 | ]; 53 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | 18 | 19 | src/ 20 | 21 | 22 | 23 | 24 | 25 | tests 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/Commands/MakeEntity.php: -------------------------------------------------------------------------------- 1 | entity = $this->argument('entity'); 42 | 43 | $this->loadSchema(); 44 | $this->loadNaming(); 45 | $this->loadServices(); 46 | } 47 | 48 | private function loadSchema() 49 | { 50 | $this->info('Loading Schema'); 51 | $this->schema = new Schema($this->option('schema')); 52 | } 53 | 54 | private function loadNaming() 55 | { 56 | $this->info('Loading Naming Classes'); 57 | 58 | $namingClasses = config('webfactor.generators.naming'); 59 | $count = count($namingClasses); 60 | $counter = 0; 61 | 62 | foreach ($namingClasses as $key => $naming) { 63 | $this->info(++$counter . '/' . $count . ' Naming Class: ' . $naming, 'v'); 64 | 65 | $namingObject = new $naming($this->entity); 66 | $this->naming[$key] = $namingObject; 67 | } 68 | 69 | $this->line(''); 70 | } 71 | 72 | private function loadServices() 73 | { 74 | $services = $this->getServicesToBeExecuted(); 75 | $progressBar = $this->output->createProgressBar(count($services)); 76 | 77 | foreach ($services as $k => $serviceClass) { 78 | $serviceInstance = new $serviceClass($this); 79 | $this->executeService($serviceInstance); 80 | 81 | $progressBar->advance(); 82 | $this->info(' '.$serviceInstance->getConsoleOutput()); 83 | } 84 | 85 | $this->line(''); 86 | } 87 | 88 | private function getServicesToBeExecuted(): array 89 | { 90 | $serviceClassesToBeExecuted = config('webfactor.generators.services', []); 91 | array_push($serviceClassesToBeExecuted, OpenIdeService::class); 92 | array_push($serviceClassesToBeExecuted, AddToGitService::class); 93 | 94 | return $serviceClassesToBeExecuted; 95 | } 96 | 97 | private function executeService(ServiceInterface $service) 98 | { 99 | $service->call(); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/Contracts/CommandAbstract.php: -------------------------------------------------------------------------------- 1 | filesToBeOpened, $file); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Contracts/NamingAbstract.php: -------------------------------------------------------------------------------- 1 | entity = $entity; 20 | } 21 | 22 | /** 23 | * @return string 24 | */ 25 | public function getFile(): string 26 | { 27 | return $this->getPath() . '/' . $this->getFileName(); 28 | } 29 | 30 | /** 31 | * @return string 32 | */ 33 | abstract public function getPath(): string; 34 | 35 | abstract public function getFileName(): string; 36 | } 37 | -------------------------------------------------------------------------------- /src/Contracts/OpenInIdeAbstract.php: -------------------------------------------------------------------------------- 1 | files = $files; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Contracts/OpenInIdeInterface.php: -------------------------------------------------------------------------------- 1 | 'setCrudFieldOptions', 29 | 'column' => 'setCrudColumnOptions', 30 | 'rule' => 'setValidationRule', 31 | ]; 32 | 33 | /** 34 | * SchemaFieldAbstract constructor. 35 | * 36 | * @param array $fieldOptions 37 | * @param array $crudOptions 38 | */ 39 | public function __construct(array $fieldOptions, array $crudOptions = []) 40 | { 41 | $this->name = $this->crudField['name'] = $this->crudColumn['name'] = $this->migrationField['name'] = $fieldOptions['name']; 42 | 43 | $this->setMigrationField($fieldOptions['options']); 44 | $this->parseCrudOptions($crudOptions); 45 | } 46 | 47 | /** 48 | * Go through any additionally provided CRUD (field, column or rule 49 | * 50 | * @param array $crudOptions 51 | */ 52 | private function parseCrudOptions(array $crudOptions): void 53 | { 54 | foreach ($crudOptions as $crudOption) { 55 | $this->parseCrudOption($crudOption); 56 | } 57 | } 58 | 59 | /** 60 | * Parse the given string and call the corresponding method if exists 61 | * 62 | * @param string $crudOption 63 | */ 64 | private function parseCrudOption(string $crudOption) 65 | { 66 | ['left' => $left, 'inside' => $inside] = RegexParser::parseParenthesis($crudOption); 67 | 68 | if (key_exists($left, $this->availableMethods)) { 69 | call_user_func([$this, $this->availableMethods[$left]], $inside); 70 | } 71 | } 72 | 73 | /** 74 | * Set options coming from inside the parenthesises 75 | * 76 | * @param string $variableName 77 | * @param string $options 78 | */ 79 | private function setOptions(string $variableName, string $options): void 80 | { 81 | if ($options) { 82 | foreach (explode('|', $options) as $option) { 83 | if (str_contains($option, ':')) { 84 | $option = explode(':', $option); 85 | $this->{$variableName}[$option[0]] = $option[1]; 86 | } else { 87 | $this->{$variableName}[$option] = true; 88 | } 89 | } 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/Contracts/SchemaFieldTypeInterface.php: -------------------------------------------------------------------------------- 1 | command = $command; 20 | $this->filesystem = new Filesystem(); 21 | 22 | $this->naming = $naming; 23 | 24 | if (is_null($naming) && $this->key) { 25 | $this->naming = $this->command->naming[$this->key]; 26 | } 27 | } 28 | 29 | protected function addGeneratedFileToIdeStack() 30 | { 31 | if ($file = $this->command->naming[$this->key]->getFile()) { 32 | $this->command->addFile($this->getSplFile($file)); 33 | } 34 | } 35 | 36 | private function getSplFile(string $pathToFile): \SplFileInfo 37 | { 38 | $splFile = new \SplFileInfo($pathToFile); 39 | 40 | if ($splFile->isFile()) { 41 | return $splFile; 42 | } 43 | 44 | return null; 45 | } 46 | 47 | public function getConsoleOutput() 48 | { 49 | return 'Handling ' . $this->key; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Contracts/ServiceInterface.php: -------------------------------------------------------------------------------- 1 | app->runningInConsole()) { 21 | $this->commands([ 22 | MakeEntity::class, 23 | ]); 24 | 25 | $this->publishes([ 26 | __DIR__ . '/../config/generators.php' => config_path('webfactor/generators.php'), 27 | ], 'config'); 28 | } 29 | 30 | $this->mergeConfigFrom( 31 | __DIR__ . '/../config/generators.php', 'webfactor.generators' 32 | ); 33 | } 34 | 35 | /** 36 | * Register any package services. 37 | * 38 | * @return void 39 | */ 40 | public function register() 41 | { 42 | // 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Helper/RegexParser.php: -------------------------------------------------------------------------------- 1 | $match[1] ?? $string, 21 | 'inside' => $match[3] ?? '', 22 | ]; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Helper/ShortSyntaxArray.php: -------------------------------------------------------------------------------- 1 | \n[^\S\n]*\[/m", ' => [', $export); 20 | $export = preg_replace("/ => \[\n[^\S\n]*\]/m", ' => []', $export); 21 | $spaces = str_repeat(' ', $indent); 22 | $export = preg_replace("/([ ]{2})(?![^ ])/m", $spaces, $export); 23 | $export = preg_replace("/^([ ]{2})/m", $spaces, $export); 24 | 25 | if ($removeNumericIndex) { 26 | $export = preg_replace("/([0-9]+) => /m", '', $export); 27 | } 28 | 29 | return $export; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Recipes/PhpStormOpener.php: -------------------------------------------------------------------------------- 1 | files as $file) { 16 | exec('pstorm ' . $file->getPathname()); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Recipes/SublimeOpener.php: -------------------------------------------------------------------------------- 1 | files as $file) { 16 | exec('subl ' . $file->getPathname()); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Recipes/VSCodeOpener.php: -------------------------------------------------------------------------------- 1 | files as $file) { 16 | exec('code ' . $file->getPathname()); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Schemas/FieldTypes/DateType.php: -------------------------------------------------------------------------------- 1 | 'date', 13 | ]; 14 | 15 | public $crudColumn = [ 16 | 'type' => 'date', 17 | ]; 18 | 19 | public $crudField = [ 20 | 'type' => 'date', 21 | ]; 22 | } 23 | -------------------------------------------------------------------------------- /src/Schemas/FieldTypes/NumberType.php: -------------------------------------------------------------------------------- 1 | 'integer', 13 | ]; 14 | 15 | public $crudColumn = [ 16 | 'type' => 'number', 17 | ]; 18 | 19 | public $crudField = [ 20 | 'type' => 'number', 21 | ]; 22 | } 23 | -------------------------------------------------------------------------------- /src/Schemas/FieldTypes/StringType.php: -------------------------------------------------------------------------------- 1 | 'string', 13 | ]; 14 | 15 | public $crudColumn = [ 16 | 'type' => 'text', 17 | ]; 18 | 19 | public $crudField = [ 20 | 'type' => 'text', 21 | ]; 22 | } 23 | -------------------------------------------------------------------------------- /src/Schemas/FieldTypes/SummernoteType.php: -------------------------------------------------------------------------------- 1 | 'text', 13 | ]; 14 | 15 | public $crudColumn = [ 16 | 'type' => 'text', 17 | ]; 18 | 19 | public $crudField = [ 20 | 'type' => 'summernote', 21 | ]; 22 | } 23 | -------------------------------------------------------------------------------- /src/Schemas/FieldTypes/TextType.php: -------------------------------------------------------------------------------- 1 | 'text', 13 | ]; 14 | 15 | public $crudColumn = [ 16 | 'type' => 'text', 17 | ]; 18 | 19 | public $crudField = [ 20 | 'type' => 'text', 21 | ]; 22 | } 23 | -------------------------------------------------------------------------------- /src/Schemas/Naming/CrudController.php: -------------------------------------------------------------------------------- 1 | getAppNamespace() . 'Http\\Controllers\\Admin'; 17 | } 18 | 19 | /** 20 | * @return string 21 | */ 22 | public function getClassName(): string 23 | { 24 | return ucfirst($this->entity) . 'CrudController'; 25 | } 26 | 27 | /** 28 | * @return string 29 | */ 30 | public function getFileName(): string 31 | { 32 | return $this->getClassName() . '.php'; 33 | } 34 | 35 | /** 36 | * @return string 37 | */ 38 | public function getPath(): string 39 | { 40 | return app_path($this->path); 41 | } 42 | 43 | /** 44 | * @return string 45 | */ 46 | public function getRelativeFilePath(): string 47 | { 48 | return str_replace("\\", '/', $this->getAppNamespace()).$this->path.'/'.$this->getFileName(); 49 | } 50 | 51 | /** 52 | * @return string 53 | */ 54 | public function getStub(): string 55 | { 56 | return __DIR__ . '/../../../stubs/crud-controller.stub'; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Schemas/Naming/CrudModel.php: -------------------------------------------------------------------------------- 1 | getAppNamespace() . 'Models'; 17 | } 18 | 19 | /** 20 | * @return string 21 | */ 22 | public function getClassName(): string 23 | { 24 | return ucfirst($this->entity); 25 | } 26 | 27 | /** 28 | * @return string 29 | */ 30 | public function getFileName(): string 31 | { 32 | return $this->getClassName() . '.php'; 33 | } 34 | 35 | /** 36 | * @return string 37 | */ 38 | public function getPath(): string 39 | { 40 | return app_path($this->path); 41 | } 42 | 43 | /** 44 | * @return string 45 | */ 46 | public function getRelativeFilePath(): string 47 | { 48 | return str_replace("\\", '/', $this->getAppNamespace()).$this->path.'/'.$this->getFileName(); 49 | } 50 | 51 | /** 52 | * @return string 53 | */ 54 | public function getStub(): string 55 | { 56 | return __DIR__ . '/../../../stubs/crud-model.stub'; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Schemas/Naming/CrudRequest.php: -------------------------------------------------------------------------------- 1 | getAppNamespace() . 'Http\\Requests\\Admin'; 17 | } 18 | 19 | /** 20 | * @return string 21 | */ 22 | public function getClassName(): string 23 | { 24 | return ucfirst($this->entity) . 'Request'; 25 | } 26 | 27 | /** 28 | * @return string 29 | */ 30 | public function getFileName(): string 31 | { 32 | return $this->getClassName() . '.php'; 33 | } 34 | 35 | /** 36 | * @return string 37 | */ 38 | public function getPath(): string 39 | { 40 | return app_path($this->path); 41 | } 42 | 43 | /** 44 | * @return string 45 | */ 46 | public function getRelativeFilePath(): string 47 | { 48 | return str_replace("\\", '/', $this->getAppNamespace()).$this->path.'/'.$this->getFileName(); 49 | } 50 | 51 | /** 52 | * @return string 53 | */ 54 | public function getStub(): string 55 | { 56 | return __DIR__ . '/../../../stubs/crud-request.stub'; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Schemas/Naming/Factory.php: -------------------------------------------------------------------------------- 1 | entity) . 'Factory'; 15 | } 16 | 17 | /** 18 | * @return string 19 | */ 20 | public function getFileName(): string 21 | { 22 | return $this->getName() . '.php'; 23 | } 24 | 25 | /** 26 | * @return string 27 | */ 28 | public function getPath(): string 29 | { 30 | return database_path('factories'); 31 | } 32 | 33 | /** 34 | * @return string 35 | */ 36 | public function getRelativeFilePath(): string 37 | { 38 | return 'database/factories/'.$this->getFileName(); 39 | } 40 | 41 | /** 42 | * @return string 43 | */ 44 | public function getStub(): string 45 | { 46 | return __DIR__ . '/../../../stubs/factory.stub'; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Schemas/Naming/LanguageFile.php: -------------------------------------------------------------------------------- 1 | entity); 15 | } 16 | 17 | /** 18 | * @return string 19 | */ 20 | public function getSingular(): string 21 | { 22 | return ucfirst($this->entity); 23 | } 24 | 25 | /** 26 | * @return string 27 | */ 28 | public function getPlural(): string 29 | { 30 | return ucfirst(str_plural($this->entity)); 31 | } 32 | 33 | /** 34 | * @return string 35 | */ 36 | public function getFileName(): string 37 | { 38 | return 'models.php'; 39 | } 40 | 41 | /** 42 | * @return string 43 | */ 44 | public function getPath(): string 45 | { 46 | return resource_path('lang/' . \Lang::locale()); 47 | } 48 | 49 | /** 50 | * @return string 51 | */ 52 | public function getRelativeFilePath(): string 53 | { 54 | return 'resources/lang/'.\Lang::locale().'/'.$this->getFileName(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Schemas/Naming/Migration.php: -------------------------------------------------------------------------------- 1 | setFileName(); 21 | } 22 | 23 | /** 24 | * @return string 25 | */ 26 | public function getClassName(): string 27 | { 28 | return 'Create' . ucfirst(str_plural($this->entity)) . 'Table'; 29 | } 30 | 31 | /** 32 | * @return string 33 | */ 34 | public function getTableName(): string 35 | { 36 | return snake_case(str_plural($this->entity)); 37 | } 38 | 39 | /** 40 | * @return void 41 | */ 42 | public function setFileName(): void 43 | { 44 | $this->fileName = Carbon::now()->format('Y_m_d_His') . '_' . snake_case($this->getClassName()) . '.php'; 45 | } 46 | 47 | /** 48 | * @return string 49 | */ 50 | public function getFileName(): string 51 | { 52 | return $this->fileName; 53 | } 54 | 55 | /** 56 | * @return string 57 | */ 58 | public function getPath(): string 59 | { 60 | return database_path('migrations'); 61 | } 62 | 63 | /** 64 | * @return string 65 | */ 66 | public function getRelativeFilePath(): string 67 | { 68 | return 'database/migrations/'.$this->getFileName(); 69 | } 70 | 71 | /** 72 | * @return string 73 | */ 74 | public function getStub(): string 75 | { 76 | return __DIR__ . '/../../../stubs/migration.stub'; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Schemas/Naming/RouteFile.php: -------------------------------------------------------------------------------- 1 | entity); 15 | } 16 | 17 | /** 18 | * @return string 19 | */ 20 | public function getFileName(): string 21 | { 22 | return 'custom.php'; 23 | } 24 | 25 | /** 26 | * @return string 27 | */ 28 | public function getPath(): string 29 | { 30 | return base_path('routes/backpack'); 31 | } 32 | 33 | /** 34 | * @return string 35 | */ 36 | public function getRelativeFilePath(): string 37 | { 38 | return 'routes/backpack/'.$this->getFileName(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Schemas/Naming/Seeder.php: -------------------------------------------------------------------------------- 1 | entity); 15 | } 16 | 17 | /** 18 | * @return string 19 | */ 20 | public function getClassName(): string 21 | { 22 | return ucfirst($this->entity) . 'Seeder'; 23 | } 24 | 25 | /** 26 | * @return string 27 | */ 28 | public function getFileName(): string 29 | { 30 | return $this->getName() . 'Seeder.php'; 31 | } 32 | 33 | /** 34 | * @return string 35 | */ 36 | public function getPath(): string 37 | { 38 | return database_path('seeds'); 39 | } 40 | 41 | /** 42 | * @return string 43 | */ 44 | public function getRelativeFilePath(): string 45 | { 46 | return 'database/seeds/'.$this->getFileName(); 47 | } 48 | 49 | /** 50 | * @return string 51 | */ 52 | public function getStub(): string 53 | { 54 | return __DIR__ . '/../../../stubs/seeder.stub'; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Schemas/Naming/Sidebar.php: -------------------------------------------------------------------------------- 1 | entity); 17 | } 18 | 19 | /** 20 | * @return string 21 | */ 22 | public function getFileName(): string 23 | { 24 | return 'sidebar_content.blade.php'; 25 | } 26 | 27 | /** 28 | * @return string 29 | */ 30 | public function getPath(): string 31 | { 32 | return resource_path($this->path); 33 | } 34 | 35 | /** 36 | * @return string 37 | */ 38 | public function getRelativeFilePath(): string 39 | { 40 | return 'resources/'.$this->path.'/'.$this->getFileName(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Schemas/Schema.php: -------------------------------------------------------------------------------- 1 | parseSchemaFields($this->getSchemaFieldsFromSchemaString($schema)); 17 | } 18 | 19 | /** 20 | * @return Collection 21 | */ 22 | public function getStructure(): Collection 23 | { 24 | return collect($this->structure); 25 | } 26 | 27 | private function getSchemaFieldsFromSchemaString(string $schema): array 28 | { 29 | return explode(',', $schema); 30 | } 31 | 32 | private function parseSchemaFields(array $schemaFields): void 33 | { 34 | foreach ($schemaFields as $schemaField) { 35 | $this->parseSchemaField($schemaField); 36 | } 37 | } 38 | 39 | private function parseSchemaField(string $schemaField): void 40 | { 41 | $schemaFieldParts = explode(';', $schemaField); 42 | 43 | $this->setSchemaField($this->parseMigration(array_shift($schemaFieldParts)), $schemaFieldParts); 44 | } 45 | 46 | private function parseMigration(string $migrationString): array 47 | { 48 | ['left' => $left, 'inside' => $inside] = RegexParser::parseParenthesis($migrationString); 49 | [$name, $type] = explode(':', $left); 50 | 51 | return [ 52 | 'name' => $name, 53 | 'type' => $type, 54 | 'options' => $inside, 55 | ]; 56 | } 57 | 58 | private function setSchemaField(array $migrationOptions, array $crudOptions): void 59 | { 60 | if ($schemaFieldType = $this->getSchemaFieldType($migrationOptions, $crudOptions)) { 61 | array_push($this->structure, $schemaFieldType); 62 | } 63 | } 64 | 65 | protected function getSchemaFieldType(array $migrationOptions, array $crudOptions): ?SchemaFieldTypeInterface 66 | { 67 | $typeClass = config('webfactor.generators.fieldTypes.'. $migrationOptions['type']); 68 | 69 | if (class_exists($typeClass)) { 70 | return $this->loadMigrationFieldType(new $typeClass($migrationOptions, $crudOptions)); 71 | } 72 | 73 | return null; 74 | } 75 | 76 | private function loadMigrationFieldType(SchemaFieldTypeInterface $fieldType): SchemaFieldTypeInterface 77 | { 78 | return $fieldType; 79 | } 80 | 81 | public function getFieldNames() 82 | { 83 | return $this->getStructure()->pluck('name'); 84 | } 85 | 86 | public function getMigrationFields() 87 | { 88 | return $this->getStructure()->pluck('migrationField'); 89 | } 90 | 91 | public function getCrudFields() 92 | { 93 | return $this->getStructure()->pluck('crudField'); 94 | } 95 | 96 | public function getCrudColumns() 97 | { 98 | return $this->getStructure()->pluck('crudColumn'); 99 | } 100 | 101 | public function getValidationRules() 102 | { 103 | return $this->getStructure()->pluck('validationRule', 'name'); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/Services/AddToGitService.php: -------------------------------------------------------------------------------- 1 | shouldPerformService() ? 'Changes added to git' : 'Changes were not added to git'; 13 | } 14 | 15 | public function shouldPerformService() 16 | { 17 | return $this->command->option('git'); 18 | } 19 | 20 | public function call() 21 | { 22 | if ($this->shouldPerformService()) { 23 | foreach ($this->command->filesToBeOpened as $file) { 24 | exec('git add '.$file->getPathname()); 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Services/BackpackCrudControllerService.php: -------------------------------------------------------------------------------- 1 | command->naming[$this->key]->getRelativeFilePath(); 20 | } 21 | 22 | protected function buildFileContent() 23 | { 24 | $this->replaceClassNamespace(); 25 | $this->replaceClassName(); 26 | $this->replaceModelRelatedStrings(); 27 | $this->replaceRequestRelatedStrings(); 28 | $this->replaceLanguageFileRelatedStrings(); 29 | $this->replaceRouteFileRelatedStrings(); 30 | $this->replaceFieldStrings(); 31 | $this->replaceColumnStrings(); 32 | } 33 | 34 | protected function replaceModelRelatedStrings() 35 | { 36 | $this->fileContent = str_replace('__model_namespace__', $this->command->naming['crudModel']->getNamespace(), $this->fileContent); 37 | $this->fileContent = str_replace('__model_class__', $this->command->naming['crudModel']->getClassName(), $this->fileContent); 38 | } 39 | 40 | protected function replaceRequestRelatedStrings() 41 | { 42 | $this->fileContent = str_replace('__request_namespace__', $this->command->naming['crudRequest']->getNamespace(), $this->fileContent); 43 | $this->fileContent = str_replace('__request_class__', $this->command->naming['crudRequest']->getClassName(), $this->fileContent); 44 | } 45 | 46 | protected function replaceLanguageFileRelatedStrings() 47 | { 48 | $this->fileContent = str_replace('__languagefile_key__', $this->command->naming['languageFile']->getName(), $this->fileContent); 49 | } 50 | 51 | protected function replaceRouteFileRelatedStrings() 52 | { 53 | $this->fileContent = str_replace('__route_name__', $this->command->naming['routeFile']->getName(), $this->fileContent); 54 | } 55 | 56 | protected function replaceFieldStrings() 57 | { 58 | $this->fileContent = str_replace('__fields__', ShortSyntaxArray::parse($this->command->schema->getCrudFields()->toArray()), $this->fileContent); 59 | } 60 | 61 | protected function replaceColumnStrings() 62 | { 63 | $this->fileContent = str_replace('__columns__', ShortSyntaxArray::parse($this->command->schema->getCrudColumns()->toArray()), $this->fileContent); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Services/BackpackCrudModelService.php: -------------------------------------------------------------------------------- 1 | command->naming[$this->key]->getRelativeFilePath(); 19 | } 20 | 21 | protected function buildFileContent() 22 | { 23 | $this->replaceClassNamespace(); 24 | $this->replaceClassName(); 25 | $this->replaceTableName(); 26 | $this->replaceFillable(); 27 | } 28 | 29 | protected function replaceFillable() 30 | { 31 | $fillables = $this->command->schema->getStructure() 32 | ->map(function ($item) { 33 | return "'" . $item->name . "'"; 34 | }); 35 | 36 | $this->fileContent = str_replace('__fillable__', $fillables->implode(', '), $this->fileContent); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Services/BackpackCrudRequestService.php: -------------------------------------------------------------------------------- 1 | command->naming[$this->key]->getRelativeFilePath(); 20 | } 21 | 22 | protected function buildFileContent() 23 | { 24 | $this->replaceClassNamespace(); 25 | $this->replaceClassName(); 26 | $this->replaceValidationRules(); 27 | } 28 | 29 | protected function replaceValidationRules() 30 | { 31 | $this->fileContent = str_replace('__rules__', ShortSyntaxArray::parse($this->command->schema->getValidationRules()->toArray(), true, 12), $this->fileContent); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Services/FactoryService.php: -------------------------------------------------------------------------------- 1 | command->naming[$this->key]->getRelativeFilePath(); 18 | } 19 | 20 | protected function buildFileContent() 21 | { 22 | $this->replaceModelRelatedStrings(); 23 | } 24 | 25 | protected function replaceModelRelatedStrings() 26 | { 27 | $this->fileContent = str_replace('__model_namespace__', $this->command->naming['crudModel']->getNamespace(), $this->fileContent); 28 | $this->fileContent = str_replace('__model_class__', $this->command->naming['crudModel']->getClassName(), $this->fileContent); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Services/LanguageFileService.php: -------------------------------------------------------------------------------- 1 | command->naming[$this->key]->getRelativeFilePath(); 19 | } 20 | 21 | /** 22 | * Build the language file. 23 | * 24 | * @param string $name 25 | * 26 | * @return string 27 | */ 28 | private function buildFileContent() 29 | { 30 | if ($this->filesystem->exists($this->naming->getFile())) { 31 | $translation = include $this->naming->getFile(); 32 | } 33 | 34 | if (!isset($translation)) { 35 | $translation = []; 36 | } 37 | 38 | $translation = array_add($translation, $this->naming->getName(), [ 39 | 'singular' => $this->naming->getSingular(), 40 | 'plural' => $this->naming->getPlural(), 41 | ]); 42 | 43 | $this->fileContent = $this->getTranslationFileContent($translation); 44 | } 45 | 46 | private function getTranslationFileContent(array $translation) 47 | { 48 | $content = ShortSyntaxArray::parse($translation); 49 | 50 | return <<command->naming[$this->key]->getRelativeFilePath(); 19 | } 20 | 21 | public function call() 22 | { 23 | $this->generateFile(); 24 | $this->addGeneratedFileToIdeStack(); 25 | 26 | if ($this->command->option('migrate')) { 27 | $this->command->call('migrate'); 28 | } 29 | } 30 | 31 | protected function buildFileContent() 32 | { 33 | $this->replaceClassName(); 34 | $this->replaceTableName(); 35 | $this->replaceMigrationFields(); 36 | } 37 | 38 | /** 39 | * Replace migration fields in stub file. 40 | * 41 | * @return string 42 | */ 43 | protected function replaceMigrationFields(): void 44 | { 45 | $this->fileContent = str_replace('__migration_fields__', $this->generateMigrationFields(), $this->fileContent); 46 | } 47 | 48 | /** 49 | * Generates the migration fields from schema 50 | * 51 | * @return string 52 | */ 53 | protected function generateMigrationFields(): string 54 | { 55 | $migrationFields = ''; 56 | 57 | foreach ($this->command->schema->getMigrationFields() as $migrationField) { 58 | $migrationFields .= ' $table->' . $migrationField['type'] . '(\'' . $migrationField['name'] . '\')'; 59 | unset($migrationField['type'], $migrationField['name']); 60 | 61 | if (!empty($migrationField)) { 62 | foreach ($migrationField as $key => $item) { 63 | $migrationFields .= '->' . $key . '(' . ((!is_bool($item)) ? '\'' . $item . '\'' : '') . ')'; 64 | } 65 | } 66 | 67 | $migrationFields .= ";" . PHP_EOL; 68 | } 69 | 70 | return $migrationFields; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Services/OpenIdeService.php: -------------------------------------------------------------------------------- 1 | getIde(); 13 | 14 | return $ide ? 'Opening all generated or edited files in '.$ide : 'Editor not defined - not opening files in IDE'; 15 | } 16 | 17 | public function call() 18 | { 19 | if ($this->getIde()) { 20 | return $this->openInIde(); 21 | } 22 | } 23 | 24 | protected function getIde() 25 | { 26 | return $this->command->option('ide') ?? env('APP_EDITOR') ?? config('app.editor') ?? false; 27 | } 28 | 29 | protected function openInIde() 30 | { 31 | if ($ideClass = config('webfactor.generators.ides.' . $this->getIde())) { 32 | (new $ideClass($this->command->filesToBeOpened))->open(); 33 | 34 | return; 35 | } 36 | 37 | $this->command->error('There is no opener class for ide ' . $this->getIde() . ''); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Services/RouteService.php: -------------------------------------------------------------------------------- 1 | command->naming[$this->key]->getRelativeFilePath(); 15 | } 16 | 17 | public function call() 18 | { 19 | $routeFile = $this->naming->getFile(); 20 | 21 | if ($this->filesystem->exists($routeFile)) { 22 | $this->addRoute($routeFile); 23 | $this->addGeneratedFileToIdeStack(); 24 | } 25 | } 26 | 27 | private function getRouteString() 28 | { 29 | return 'CRUD::resource(\'' . $this->naming->getName() . '\', \'' . $this->command->naming['crudController']->getClassName() . '\');'; 30 | } 31 | 32 | private function addRoute($routeFile) 33 | { 34 | $old_file_content = $this->filesystem->get($routeFile); 35 | 36 | // insert the given code before the file's last line 37 | $file_lines = preg_split('/\r\n|\r|\n/', $old_file_content); 38 | if ($end_line_number = $this->getRoutesFileEndLine($file_lines)) { 39 | $file_lines[$end_line_number + 1] = $file_lines[$end_line_number]; 40 | $file_lines[$end_line_number] = ' ' . $this->getRouteString(); 41 | $new_file_content = implode(PHP_EOL, $file_lines); 42 | 43 | $this->filesystem->put($routeFile, $new_file_content); 44 | } else { 45 | $this->filesystem->append($routeFile, PHP_EOL . $this->getRouteString()); 46 | } 47 | } 48 | 49 | private function getRoutesFileEndLine($file_lines) 50 | { 51 | // in case the last line has not been modified at all 52 | $end_line_number = array_search('}); // this should be the absolute last line of this file', $file_lines); 53 | 54 | if ($end_line_number) { 55 | return $end_line_number; 56 | } 57 | 58 | // otherwise, in case the last line HAS been modified 59 | // return the last line that has an ending in it 60 | $possible_end_lines = array_filter($file_lines, function ($k) { 61 | return strpos($k, '});') === 0; 62 | }); 63 | 64 | if ($possible_end_lines) { 65 | end($possible_end_lines); 66 | $end_line_number = key($possible_end_lines); 67 | 68 | return $end_line_number; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Services/SeederService.php: -------------------------------------------------------------------------------- 1 | command->naming[$this->key]->getRelativeFilePath(); 18 | } 19 | 20 | protected function buildFileContent() 21 | { 22 | $this->replaceClassName(); 23 | $this->replaceModelRelatedStrings(); 24 | } 25 | 26 | protected function replaceModelRelatedStrings() 27 | { 28 | $this->fileContent = str_replace('__model_namespace__', $this->command->naming['crudModel']->getNamespace(), $this->fileContent); 29 | $this->fileContent = str_replace('__model_class__', $this->command->naming['crudModel']->getClassName(), $this->fileContent); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Services/SidebarService.php: -------------------------------------------------------------------------------- 1 | command->naming[$this->key]->getRelativeFilePath(); 15 | } 16 | 17 | public function call() 18 | { 19 | $sidebarFile = $this->naming->getFile(); 20 | 21 | if ($this->filesystem->exists($sidebarFile)) { 22 | $this->filesystem->append($sidebarFile, $this->getSidebarString()); 23 | $this->addGeneratedFileToIdeStack(); 24 | } 25 | } 26 | 27 | private function getSidebarString() 28 | { 29 | return << 32 | 33 | {{ trans('models.{$this->command->naming['languageFile']->getName()}.plural') }} 34 | 35 | 36 | FILE; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Traits/CanGenerateFile.php: -------------------------------------------------------------------------------- 1 | generateFile(); 12 | $this->addGeneratedFileToIdeStack(); 13 | } 14 | 15 | /** 16 | * Generate the file and save it according to specified naming. 17 | * 18 | * @return void 19 | */ 20 | protected function generateFile(): void 21 | { 22 | if (method_exists($this->naming, 'getStub')) { 23 | $this->loadStubFile($this->naming->getStub()); 24 | } 25 | 26 | $this->buildFileContent(); 27 | 28 | if (!$this->filesystem->isDirectory($this->naming->getPath())) { 29 | $this->filesystem->makeDirectory($this->naming->getPath(), 0755, true); 30 | } 31 | 32 | $this->filesystem->put($this->naming->getFile(), $this->fileContent); 33 | } 34 | 35 | protected function loadStubFile(string $stubFile): void 36 | { 37 | try { 38 | $this->fileContent = $this->filesystem->get($stubFile); 39 | } catch (FileNotFoundException $exception) { 40 | $this->command->error('Could not find stub file: ' . $stubFile); 41 | } 42 | } 43 | 44 | /** 45 | * Replace the class namespace in stub file. 46 | * 47 | * @return string 48 | */ 49 | protected function replaceClassNamespace(): void 50 | { 51 | $this->fileContent = str_replace('__class_namespace__', $this->naming->getNamespace(), $this->fileContent); 52 | } 53 | 54 | /** 55 | * Replace the class name in stub file. 56 | * 57 | * @return string 58 | */ 59 | protected function replaceClassName(): void 60 | { 61 | $this->fileContent = str_replace('__class_name__', $this->naming->getClassName(), $this->fileContent); 62 | } 63 | 64 | /** 65 | * Replace the table name in stub file. 66 | * 67 | * @return string 68 | */ 69 | protected function replaceTableName(): void 70 | { 71 | $this->fileContent = str_replace('__table_name__', $this->command->naming['migration']->getTableName(), $this->fileContent); 72 | } 73 | 74 | /** 75 | * Get the full path to the generated file. 76 | * 77 | * @return string 78 | */ 79 | protected function getFilePath(): string 80 | { 81 | return $this->command->naming[$this->key]->getFile(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/Traits/CrudColumn.php: -------------------------------------------------------------------------------- 1 | 'text', 9 | ]; 10 | 11 | public function getCrudColumn(): array 12 | { 13 | return $this->crudColumn; 14 | } 15 | 16 | private function setCrudColumnOptions(string $crudColumnOptions) 17 | { 18 | $this->setOptions('crudColumn', $crudColumnOptions); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Traits/CrudField.php: -------------------------------------------------------------------------------- 1 | 'text', 9 | ]; 10 | 11 | public function getCrudField(): array 12 | { 13 | return $this->crudField; 14 | } 15 | 16 | private function setCrudFieldOptions(string $crudFieldOptions) 17 | { 18 | $this->setOptions('crudField', $crudFieldOptions); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Traits/MigrationField.php: -------------------------------------------------------------------------------- 1 | 'string', 9 | ]; 10 | 11 | public function getMigrationField(): array 12 | { 13 | return $this->migrationField; 14 | } 15 | 16 | private function setMigrationField(string $migrationFieldOptions) 17 | { 18 | $this->setOptions('migrationField', $migrationFieldOptions); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Traits/ValidationRule.php: -------------------------------------------------------------------------------- 1 | validationRule; 12 | } 13 | 14 | private function setValidationRule(string $validationRule) 15 | { 16 | $this->validationRule = $validationRule; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /stubs/crud-controller.stub: -------------------------------------------------------------------------------- 1 | crud->setModel(__model_class__::class); 22 | $this->crud->setRoute(config('backpack.base.route_prefix') . '/__route_name__'); 23 | $this->crud->setEntityNameStrings(trans('models.__languagefile_key__.singular'), trans('models.__languagefile_key__.plural')); 24 | 25 | /* 26 | |-------------------------------------------------------------------------- 27 | | OPTIONAL CRUD SETTINGS 28 | |-------------------------------------------------------------------------- 29 | */ 30 | 31 | $this->crud->setRequiredFields(StoreRequest::class, 'create'); 32 | $this->crud->setRequiredFields(UpdateRequest::class, 'edit'); 33 | 34 | /* 35 | |-------------------------------------------------------------------------- 36 | | CRUD COLUMNS 37 | |-------------------------------------------------------------------------- 38 | */ 39 | 40 | $this->crud->addColumns(__columns__); 41 | 42 | /* 43 | |-------------------------------------------------------------------------- 44 | | CRUD FIELDS 45 | |-------------------------------------------------------------------------- 46 | */ 47 | 48 | $this->crud->addFields(__fields__); 49 | 50 | /* 51 | |-------------------------------------------------------------------------- 52 | | CRUD FILTERS 53 | |-------------------------------------------------------------------------- 54 | */ 55 | 56 | // 57 | } 58 | 59 | public function store(StoreRequest $request) 60 | { 61 | // your additional operations before save here 62 | $redirect_location = parent::storeCrud($request); 63 | // your additional operations after save here 64 | // use $this->data['entry'] or $this->crud->entry 65 | return $redirect_location; 66 | } 67 | 68 | public function update(UpdateRequest $request) 69 | { 70 | // your additional operations before save here 71 | $redirect_location = parent::updateCrud($request); 72 | // your additional operations after save here 73 | // use $this->data['entry'] or $this->crud->entry 74 | return $redirect_location; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /stubs/crud-model.stub: -------------------------------------------------------------------------------- 1 | check(); 18 | } 19 | 20 | /** 21 | * Get the validation rules that apply to the request. 22 | * 23 | * @return array 24 | */ 25 | public function rules() 26 | { 27 | return __rules__; 28 | } 29 | 30 | /** 31 | * Get the validation attributes that apply to the request. 32 | * 33 | * @return array 34 | */ 35 | public function attributes() 36 | { 37 | return [ 38 | // 39 | ]; 40 | } 41 | 42 | /** 43 | * Get the validation messages that apply to the request. 44 | * 45 | * @return array 46 | */ 47 | public function messages() 48 | { 49 | return [ 50 | // 51 | ]; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /stubs/factory.stub: -------------------------------------------------------------------------------- 1 | define(__model_namespace__\__model_class__::class, function (Faker $faker) { 7 | return [ 8 | // 9 | ]; 10 | }); 11 | -------------------------------------------------------------------------------- /stubs/migration.stub: -------------------------------------------------------------------------------- 1 | increments('id'); 17 | __migration_fields__ 18 | $table->timestamps(); 19 | }); 20 | } 21 | 22 | /** 23 | * Reverse the migrations. 24 | * 25 | * @return void 26 | */ 27 | public function down() 28 | { 29 | Schema::drop('__table_name__'); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /stubs/seeder.stub: -------------------------------------------------------------------------------- 1 | create(); 16 | } 17 | } 18 | --------------------------------------------------------------------------------