├── .github
├── FUNDING.yml
└── workflows
│ └── run-tests.yml
├── .gitignore
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── composer.json
├── config
└── laravel_generator.php
├── locale
├── ar
│ ├── auth.php
│ ├── crud.php
│ └── messages.php
├── en
│ ├── auth.php
│ ├── crud.php
│ └── messages.php
├── es
│ ├── auth.php
│ ├── crud.php
│ └── messages.php
├── fa
│ ├── auth.php
│ ├── crud.php
│ └── messages.php
├── id
│ ├── auth.php
│ ├── crud.php
│ └── messages.php
├── pl
│ ├── auth.php
│ ├── crud.php
│ └── messages.php
└── zh_CN
│ ├── auth.php
│ ├── crud.php
│ └── messages.php
├── made-with-generator.md
├── phpunit.xml.dist
├── samples
└── fields_sample.json
├── src
├── Commands
│ ├── API
│ │ ├── APIControllerGeneratorCommand.php
│ │ ├── APIGeneratorCommand.php
│ │ ├── APIRequestsGeneratorCommand.php
│ │ └── TestsGeneratorCommand.php
│ ├── APIScaffoldGeneratorCommand.php
│ ├── BaseCommand.php
│ ├── Common
│ │ ├── MigrationGeneratorCommand.php
│ │ ├── ModelGeneratorCommand.php
│ │ └── RepositoryGeneratorCommand.php
│ ├── Publish
│ │ ├── GeneratorPublishCommand.php
│ │ ├── PublishBaseCommand.php
│ │ ├── PublishTablesCommand.php
│ │ └── PublishUserCommand.php
│ ├── RollbackGeneratorCommand.php
│ └── Scaffold
│ │ ├── ControllerGeneratorCommand.php
│ │ ├── RequestsGeneratorCommand.php
│ │ ├── ScaffoldGeneratorCommand.php
│ │ └── ViewsGeneratorCommand.php
├── Common
│ ├── FileSystem.php
│ ├── GeneratorConfig.php
│ ├── GeneratorField.php
│ └── GeneratorFieldRelation.php
├── Criteria
│ └── LimitOffsetCriteria.php
├── DTOs
│ ├── GeneratorNamespaces.php
│ ├── GeneratorOptions.php
│ ├── GeneratorPaths.php
│ ├── GeneratorPrefixes.php
│ └── ModelNames.php
├── Events
│ ├── GeneratorFileCreated.php
│ ├── GeneratorFileCreating.php
│ ├── GeneratorFileDeleted.php
│ └── GeneratorFileDeleting.php
├── Facades
│ └── FileUtils.php
├── Generators
│ ├── API
│ │ ├── APIControllerGenerator.php
│ │ ├── APIRequestGenerator.php
│ │ ├── APIResourceGenerator.php
│ │ ├── APIRoutesGenerator.php
│ │ └── APITestGenerator.php
│ ├── BaseGenerator.php
│ ├── FactoryGenerator.php
│ ├── MigrationGenerator.php
│ ├── ModelGenerator.php
│ ├── RepositoryGenerator.php
│ ├── RepositoryTestGenerator.php
│ ├── Scaffold
│ │ ├── ControllerGenerator.php
│ │ ├── MenuGenerator.php
│ │ ├── RequestGenerator.php
│ │ ├── RoutesGenerator.php
│ │ └── ViewGenerator.php
│ ├── SeederGenerator.php
│ ├── SwaggerGenerator.php
│ └── ViewServiceProviderGenerator.php
├── InfyOmGeneratorServiceProvider.php
├── Request
│ └── APIRequest.php
├── Utils
│ ├── GeneratorFieldsInputUtil.php
│ ├── HTMLFieldGenerator.php
│ ├── ResponseUtil.php
│ ├── SchemaUtil.php
│ └── TableFieldsGenerator.php
└── helpers.php
├── tests
├── Commands
│ ├── APIGeneratorCommandTest.php
│ ├── APIScaffoldGeneratorCommandTest.php
│ ├── PublishTablesCommandTest.php
│ ├── RollbackGeneratorCommandTest.php
│ └── ScaffoldGeneratorCommandTest.php
├── Generators
│ └── APIControllerGeneratorTest.php
├── Helpers
│ └── HelpersTest.php
├── Pest.php
├── TestCase.php
├── TestHelpers.php
└── fixtures
│ └── model_schema
│ └── Post.json
└── views
├── api
├── controller
│ ├── model
│ │ ├── controller.blade.php
│ │ └── controller_resource.blade.php
│ └── repository
│ │ ├── controller.blade.php
│ │ └── controller_resource.blade.php
├── docs
│ └── controller
│ │ ├── controller.blade.php
│ │ ├── destroy.blade.php
│ │ ├── index.blade.php
│ │ ├── show.blade.php
│ │ ├── store.blade.php
│ │ └── update.blade.php
├── request
│ ├── create.blade.php
│ └── update.blade.php
├── resource
│ └── resource.blade.php
├── routes.blade.php
└── test
│ ├── api_test.blade.php
│ └── api_test_trait.blade.php
├── migration.blade.php
├── model
├── factory.blade.php
├── model.blade.php
├── relationship.blade.php
└── seeder.blade.php
├── repository
├── repository.blade.php
└── repository_test.blade.php
├── scaffold
├── controller
│ ├── controller.blade.php
│ ├── controller_repository.blade.php
│ ├── index_method.blade.php
│ ├── index_method_datatable.blade.php
│ ├── index_method_livewire.blade.php
│ ├── index_method_repository.blade.php
│ ├── messages
│ │ ├── delete_success.blade.php
│ │ ├── not_found.blade.php
│ │ ├── save_success.blade.php
│ │ └── update_success.blade.php
│ └── model_not_found.blade.php
├── layouts
│ ├── datatables_css.blade.php
│ └── datatables_js.blade.php
├── request
│ ├── create.blade.php
│ └── update.blade.php
├── routes.blade.php
├── table
│ ├── datatable.blade.php
│ └── livewire.blade.php
└── user
│ ├── create_user_request.blade.php
│ ├── update_user_request.blade.php
│ ├── user_controller.blade.php
│ ├── user_controller_without_repository.blade.php
│ └── user_repository.blade.php
└── stubs
├── app_base_controller.blade.php
└── base_repository.blade.php
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | open_collective: infyomlabs
4 |
--------------------------------------------------------------------------------
/.github/workflows/run-tests.yml:
--------------------------------------------------------------------------------
1 | name: Run tests
2 |
3 | on: push
4 |
5 | jobs:
6 | php-tests:
7 | runs-on: ubuntu-latest
8 |
9 | name: Run Package Tests
10 |
11 | strategy:
12 | matrix:
13 | php: ['8.1', '8.2', '8.3']
14 |
15 | steps:
16 | - name: Checkout Code
17 | uses: actions/checkout@v2
18 |
19 | - name: Cache dependencies
20 | uses: actions/cache@v2
21 | with:
22 | path: ~/.composer/cache/files
23 | key: dependencies-composer-${{ hashFiles('composer.json') }}
24 |
25 | - name: Setup PHP
26 | uses: shivammathur/setup-php@v2
27 | with:
28 | php-version: ${{ matrix.php }}
29 | extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite
30 | coverage: none
31 |
32 | - name: Install Composer dependencies
33 | run: composer install --prefer-dist --no-interaction --no-suggest
34 |
35 | - name: Execute tests
36 | run: vendor/bin/pest
37 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor
2 | /.env
3 | composer.phar
4 | composer.lock
5 | .DS_Store
6 | Thumbs.db
7 | .idea
8 | .phpunit.result.cache
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Release Notes
2 |
3 | ## 20th Apr 2016
4 |
5 | #### New Features
6 | - Introducing [Laravel Generator Builder](http://labs.infyom.com/laravelgenerator/docs/generator-gui-interface) ([#94](https://github.com/InfyOmLabs/laravel-generator/issues/94))
7 | - Introducing Support to Generate CRUD with [AdminLTE Templates](http://labs.infyom.com/laravelgenerator/docs/templates/adminlte)
8 | - Added [Support for DataTable](http://labs.infyom.com/laravelgenerator/docs/options/scaffold-options) in both Bootstrap & AdminLTE Templates ([#50](https://github.com/InfyOmLabs/laravel-generator/issues/50))
9 | - Introducing Support for [Publishing a full Admin Panel layout](http://labs.infyom.com/laravelgenerator/docs/advanced/publish-layout)
10 | - Added [Rollback command](http://labs.infyom.com/laravelgenerator/docs/advanced/commands) to delete generated files ([#44](https://github.com/InfyOmLabs/laravel-generator/issues/44))
11 |
12 | #### Enhancements
13 | - Swagger Document Fix via AppBaseController Publish ([#101](https://github.com/InfyOmLabs/laravel-generator/issues/101))
14 |
15 | #### Fixes
16 | - Support for custom Namespace ([#98](https://github.com/InfyOmLabs/laravel-generator/issues/98))
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # InfyOm Generator Contribution Guide
2 |
3 | Thank you for considering contributing to the InfyOm Generator!
4 |
5 | #### Coding Style
6 | As this package is related to laravel, we are follows the PSR-2 coding standard and the PSR-4 autoloading standard.
7 |
8 | #### StyleCI
9 | We've integrated StyleCI. So when you submit a PR, it will automatically suggest the fix of styling. Fix it and re-submit the PR if needed.
10 |
11 | #### Pull Requests
12 | Please make all pull requests to the `develop` branch of the project.
13 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 InfyOm Labs
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 |

2 |
3 | InfyOm Laravel Generator
4 | ==========================
5 |
6 | [](https://packagist.org/packages/infyomlabs/laravel-generator)
7 | [](https://packagist.org/packages/infyomlabs/laravel-generator)
8 | [](https://packagist.org/packages/infyomlabs/laravel-generator)
9 | [](https://packagist.org/packages/infyomlabs/laravel-generator)
10 |
11 | Generate Admin Panels CRUDs and APIs in Minutes with tons of other features and customizations with 3 different themes.
12 |
13 | ## Documentation
14 |
15 | Read [Documentation](https://www.infyom.com/open-source) for detailed installation steps and usage.
16 |
17 | ## Support Us
18 |
19 | We have created [14+ Laravel packages](https://github.com/InfyOmLabs) and invested a lot of resources into creating these all packages and maintaining them.
20 |
21 | You can support us by either sponsoring us or buying one of our paid products. Or help us by spreading the word about us on social platforms via tweets and posts.
22 |
23 | ### Buy our Paid Products
24 |
25 | [](https://bit.ly/infy-gpt)
26 |
27 | You can also check out our other paid products on [CodeCanyon](https://1.envato.market/BXAnR1).
28 |
29 | ### Sponsors
30 |
31 | [Become a sponsor](https://opencollective.com/infyomlabs#sponsor) and get your logo on our README on Github with a link to your site.
32 |
33 |
34 |
35 | ### Backers
36 |
37 | [Become a backer](https://opencollective.com/infyomlabs#backer) and get your image on our README on Github with a link to your site.
38 |
39 |
40 |
41 | ### Follow Us
42 |
43 | - [Twitter](https://twitter.com/infyom)
44 | - [Facebook](https://www.facebook.com/infyom)
45 | - [LinkedIn](https://in.linkedin.com/company/infyom-technologies)
46 | - [Youtube](https://www.youtube.com/channel/UC8IvwfChD6i7Wp4yZp3tNsQ)
47 | - [Contact Us](https://infyom.com/contact-us)
48 |
49 | ## Made with InfyOm Generator
50 |
51 | Also, Do not forget to add your website to [Made with InfyOm Generator List](https://github.com/InfyOmLabs/laravel-generator/blob/develop/made-with-generator.md) list.
52 |
53 | ## Video Tutorials
54 |
55 | Checkout [Video Tutorials](https://github.com/shailesh-ladumor/infyom-laravel-generator-tutorial) - **By**: [Shailesh Ladumor](https://github.com/shailesh-ladumor)
56 |
57 | ## Security
58 |
59 | If you discover any security-related issues, create an issue using the issue tracker.
60 |
61 | ## Credits
62 |
63 | - [InfyOm Technologies](https://github.com/infyomlabs)
64 | - [All Contributors](../../contributors)
65 |
66 | ## License
67 |
68 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
69 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "infyomlabs/laravel-generator",
3 | "type": "library",
4 | "description": "InfyOm Laravel Generator",
5 | "keywords": [
6 | "laravel",
7 | "api",
8 | "model",
9 | "request",
10 | "migration",
11 | "model",
12 | "crud",
13 | "repository",
14 | "view",
15 | "test",
16 | "generator",
17 | "swagger"
18 | ],
19 | "license": "MIT",
20 | "authors": [{
21 | "name": "Mitul Golakiya",
22 | "email": "me@mitul.me"
23 | }],
24 | "require": {
25 | "php": "^8.1.0",
26 | "illuminate/support": "^10.0",
27 | "illuminate/console": "^10.0",
28 | "laracasts/flash": "^3.2.2",
29 | "laravelcollective/html": "^6.4",
30 | "symfony/var-exporter": "^6.2.5"
31 | },
32 | "require-dev": {
33 | "phpunit/phpunit": "^10.0.7",
34 | "mockery/mockery": "^1.5.1",
35 | "orchestra/testbench": "^8.0.0",
36 | "pestphp/pest": "2.x-dev",
37 | "pestphp/pest-plugin-laravel": "2.x-dev"
38 | },
39 | "autoload": {
40 | "psr-4": {
41 | "InfyOm\\Generator\\": "src/"
42 | },
43 | "files": [
44 | "src/helpers.php"
45 | ]
46 | },
47 | "autoload-dev": {
48 | "psr-4": {
49 | "Tests\\": "tests/"
50 | }
51 | },
52 | "extra": {
53 | "laravel": {
54 | "providers": [
55 | "\\InfyOm\\Generator\\InfyOmGeneratorServiceProvider"
56 | ]
57 | }
58 | },
59 | "funding": [{
60 | "type": "opencollective",
61 | "url": "https://opencollective.com/infyomlabs"
62 | }],
63 | "minimum-stability": "dev",
64 | "prefer-stable": true,
65 | "config": {
66 | "allow-plugins": {
67 | "pestphp/pest-plugin": true
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/locale/ar/auth.php:
--------------------------------------------------------------------------------
1 | 'المعلومات المدخلة لا تطابق سجلاتنا.',
17 | 'throttle' => 'محاولات دخول أكثر من اللازم. يرجى إعادة المحاولة بعد :seconds ثانية.',
18 |
19 | 'full_name' => 'الإسم الكامل',
20 | 'email' => 'البريد الإلكتروني',
21 | 'password' => 'كلمة المرور',
22 | 'confirm_password' => 'تأكيد كلمة المرور',
23 | 'remember_me' => 'تذكرني',
24 | 'sign_in' => 'تسجيل الدخول',
25 | 'sign_out' => 'تسجيل الخروج',
26 | 'register' => 'إنشاء حساب',
27 |
28 | 'login' => [
29 | 'title' => 'قم بتسجيل الدخول للبدء',
30 | 'forgot_password' => 'نسيت كلمة المرور',
31 | ],
32 |
33 | 'registration' => [
34 | 'title' => 'قم بفتح حساب جديد',
35 | 'i_agree' => 'أوافق على',
36 | 'terms' => 'الشروط',
37 | 'have_membership' => 'لدي حساب',
38 | ],
39 |
40 | 'forgot_password' => [
41 | 'title' => 'نسيت كلمة المرور؟ يمكنك هنا استعادة كلمة مرور جديدة',
42 | 'send_pwd_reset' => 'أرسل رابط استعادة كلمة المرور',
43 | ],
44 |
45 | 'reset_password' => [
46 | 'title' => 'أنت على بعد خطوة واحدة من كلمة مرورك الجديدة، قم بالحصول عليها.',
47 | 'reset_pwd_btn' => 'إستعادة كلمة المرور',
48 | ],
49 |
50 | 'confirm_passwords' => [
51 | 'title' => 'رجاءً قم بتأكيد كلمة مرورك قبل المتابعة.',
52 | 'forgot_your_password' => 'نسيت كلمة المرور؟',
53 | ],
54 |
55 | 'verify_email' => [
56 | 'title' => 'قم بتأكيد بريدك الإلكتروني',
57 | 'success' => 'تم إرسال رابط تحقق حديث إلى بريدك الإلكتروني',
58 | 'notice' => 'قبل المتابعة، يرجى تفقد البريد الإلكتروني الخاص بك للحصول على رابط التحقق. إذا لم تتلقى بريداً،',
59 | 'another_req' => 'إضغط هنا لإرسال رابط آخر',
60 | ],
61 |
62 | 'emails' => [
63 | 'password' => [
64 | 'reset_link' => 'اضغط هنا لإستعادة كلمة مرورك',
65 | ],
66 | ],
67 | ];
68 |
--------------------------------------------------------------------------------
/locale/ar/crud.php:
--------------------------------------------------------------------------------
1 | 'إضافة جديد',
6 | 'cancel' => 'إلغاء',
7 | 'create' => 'إنشاء',
8 | 'edit' => 'تعديل',
9 | 'save' => 'حفظ',
10 | 'delete' => 'جذف',
11 | 'detail' => 'التفاصيل',
12 | 'back' => 'العودة',
13 | 'search' => 'البحث',
14 | 'export' => 'تصدير',
15 | 'print' => 'طباعة',
16 | 'reset' => 'استعادة',
17 | 'reload' => 'إعادة تحميل',
18 | 'action' => 'عملية',
19 | 'id' => 'Id',
20 | 'created_at' => 'تاريخ الإنشاء',
21 | 'updated_at' => 'تاريخ آخر تعديل',
22 | 'deleted_at' => 'تاريخ الحذف',
23 | 'are_you_sure' => 'هل أنت متأكد؟',
24 | ];
25 |
--------------------------------------------------------------------------------
/locale/ar/messages.php:
--------------------------------------------------------------------------------
1 | 'تم جلب :model بنجاح.',
6 | 'saved' => 'تم حفظ :model بنجاح.',
7 | 'updated' => 'تم تعديل :model بنجاح.',
8 | 'deleted' => 'تم حذف :model بنجاح.',
9 | 'not_found' => 'لم يتم العثور على :model.',
10 |
11 | ];
12 |
--------------------------------------------------------------------------------
/locale/en/auth.php:
--------------------------------------------------------------------------------
1 | 'These credentials do not match our records.',
17 | 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',
18 |
19 | 'full_name' => 'Full Name',
20 | 'email' => 'Email',
21 | 'password' => 'Password',
22 | 'confirm_password' => 'Confirm Password',
23 | 'remember_me' => 'Remember Me',
24 | 'sign_in' => 'Sign In',
25 | 'sign_out' => 'Sign out',
26 | 'register' => 'Register',
27 |
28 | 'login' => [
29 | 'title' => 'Sign in to start your session',
30 | 'forgot_password' => 'I forgot my password',
31 | ],
32 |
33 | 'registration' => [
34 | 'title' => 'Register a new membership',
35 | 'i_agree' => 'I agree to',
36 | 'terms' => 'the terms',
37 | 'have_membership' => 'I already have a membership',
38 | ],
39 |
40 | 'forgot_password' => [
41 | 'title' => 'You forgot your password? Here you can easily retrieve a new password.',
42 | 'send_pwd_reset' => 'Send Password Reset Link',
43 | ],
44 |
45 | 'reset_password' => [
46 | 'title' => 'You are only one step a way from your new password, recover your password now.',
47 | 'reset_pwd_btn' => 'Reset Password',
48 | ],
49 |
50 | 'confirm_passwords' => [
51 | 'title' => 'Please confirm your password before continuing.',
52 | 'forgot_your_password' => 'Forgot Your Password?',
53 | ],
54 |
55 | 'verify_email' => [
56 | 'title' => 'Verify Your Email Address',
57 | 'success' => 'A fresh verification link has been sent to your email address',
58 | 'notice' => 'Before proceeding, please check your email for a verification link.If you did not receive the email,',
59 | 'another_req' => 'click here to request another',
60 | ],
61 |
62 | 'emails' => [
63 | 'password' => [
64 | 'reset_link' => 'Click here to reset your password',
65 | ],
66 | ],
67 | ];
68 |
--------------------------------------------------------------------------------
/locale/en/crud.php:
--------------------------------------------------------------------------------
1 | 'Add New',
6 | 'cancel' => 'Cancel',
7 | 'create' => 'Create',
8 | 'edit' => 'Edit',
9 | 'save' => 'Save',
10 | 'delete' => 'Delete',
11 | 'detail' => 'Detail',
12 | 'back' => 'Back',
13 | 'search' => 'Search',
14 | 'export' => 'Export',
15 | 'print' => 'Print',
16 | 'reset' => 'Reset',
17 | 'reload' => 'Reload',
18 | 'action' => 'Action',
19 | 'id' => 'Id',
20 | 'created_at' => 'Created At',
21 | 'updated_at' => 'Updated At',
22 | 'deleted_at' => 'Deleted At',
23 | 'are_you_sure' => 'Are you sure?',
24 | ];
25 |
--------------------------------------------------------------------------------
/locale/en/messages.php:
--------------------------------------------------------------------------------
1 | ':model retrieved successfully.',
6 | 'saved' => ':model saved successfully.',
7 | 'updated' => ':model updated successfully.',
8 | 'deleted' => ':model deleted successfully.',
9 | 'not_found' => ':model not found',
10 |
11 | ];
12 |
--------------------------------------------------------------------------------
/locale/es/auth.php:
--------------------------------------------------------------------------------
1 | 'Estas credenciales no coinciden con nuestros registros.',
17 | 'throttle' => 'Demasiados intentos de inicio de sesión. Por favor. inténtelo de nuevo en :seconds seconds.',
18 |
19 | 'full_name' => 'Nombre Completo',
20 | 'email' => 'Correo',
21 | 'password' => 'Contraseña',
22 | 'confirm_password' => 'Confirmar contraseña',
23 | 'remember_me' => 'Recuérdame',
24 | 'sign_in' => 'Iniciar Sesión',
25 | 'sign_out' => 'Cerrar Sesión',
26 | 'register' => 'Registrar',
27 |
28 | 'login' => [
29 | 'title' => 'Inicie la sesión',
30 | 'forgot_password' => 'He olvidado mi contraseña',
31 | 'register_membership' => 'Registrar una nueva membresía',
32 | ],
33 |
34 | 'registration' => [
35 | 'title' => 'Registrar una nueva membresía',
36 | 'i_agree' => 'Estoy de acuerdo con',
37 | 'terms' => 'Los términos',
38 | 'have_membership' => 'Ya tengo una membresía',
39 | ],
40 |
41 | 'forgot_password' => [
42 | 'title' => 'Introduzca el correo electrónico para restablecer la contraseña',
43 | 'send_pwd_reset' => 'Enviar enlace para restablecer la contraseña',
44 | ],
45 |
46 | 'reset_password' => [
47 | 'title' => 'Restablece tu contraseña',
48 | 'reset_pwd_btn' => 'Restablecer contraseña',
49 | ],
50 |
51 | 'confirm_passwords' => [
52 | 'title' => 'Por favor, confirme su contraseña antes de continuar.',
53 | 'forgot_your_password' => '¿Ha olvidado su contraseña?',
54 | ],
55 |
56 | 'verify_email' => [
57 | 'title' => 'Verifique su dirección de correo electrónico',
58 | 'success' => 'Se ha enviado un nuevo enlace de verificación a su dirección de correo electrónico',
59 | 'notice' => 'Antes de continuar, por favor revise su correo electrónico en busca de un enlace de verificación.Si no recibió el correo electrónico.',
60 | 'another_req' => 'Haga clic aquí para solicitar otro',
61 | ],
62 |
63 | 'emails' => [
64 | 'password' => [
65 | 'reset_link' => 'Haga clic aquí para restablecer su contraseña',
66 | ],
67 | ],
68 | ];
69 |
--------------------------------------------------------------------------------
/locale/es/crud.php:
--------------------------------------------------------------------------------
1 | 'Añadir nuevo',
6 | 'cancel' => 'Cancelar',
7 | 'create' => 'Crear',
8 | 'edit' => 'Editar',
9 | 'save' => 'Guardar',
10 | 'detail' => 'Detalle',
11 | 'back' => 'Volver',
12 | 'search' => 'Buscar',
13 | 'export' => 'Exportar',
14 | 'print' => 'Imprimir',
15 | 'reset' => 'Reiniciar',
16 | 'reload' => 'Recargar',
17 | 'action' => 'Acción',
18 | 'id' => 'Id',
19 | 'created_at' => 'Creado en',
20 | 'updated_at' => 'Actualizado en',
21 | 'deleted_at' => 'Eliminado en',
22 | 'are_you_sure' => '¿Estás seguro?',
23 | ];
24 |
--------------------------------------------------------------------------------
/locale/es/messages.php:
--------------------------------------------------------------------------------
1 | ':model recuperado con éxito.',
6 | 'saved' => ':model guardado con éxito.',
7 | 'updated' => ':model actualizado con éxito.',
8 | 'deleted' => ':model borrado con éxito.',
9 | 'not_found' => ':model not encontrado',
10 |
11 | ];
12 |
--------------------------------------------------------------------------------
/locale/fa/auth.php:
--------------------------------------------------------------------------------
1 | 'این اطلاعات با سوابق ما مطابقت ندارد.',
17 | 'throttle' => 'تلاش برای ورود به سیستم بسیار زیاد یود.لطفا در :seconds ثانیه دیگر امتحان کنید.',
18 |
19 | 'full_name' => 'نام و نام خانوادگی',
20 | 'email' => 'پست الکترونیک',
21 | 'password' => 'کلمه عبور',
22 | 'confirm_password' => 'تایید رمز عبور',
23 | 'remember_me' => 'مرا به خاطر بسپار',
24 | 'sign_in' => 'ورود',
25 | 'sign_out' => 'خروج',
26 | 'register' => 'ثبت نام',
27 |
28 | 'login' => [
29 | 'title' => 'برای شروع جلسه خود وارد سیستم شوید',
30 | 'forgot_password' => 'رمز عبورم را فراموش کردم',
31 | 'register_membership' => 'عضویت جدیدی ثبت کنید',
32 | ],
33 |
34 | 'registration' => [
35 | 'title' => 'عضویت جدیدی ثبت کنید',
36 | 'i_agree' => 'موافقم',
37 | 'terms' => 'شرایط',
38 | 'have_membership' => 'من قبلاً عضويت داشتم',
39 | ],
40 |
41 | 'forgot_password' => [
42 | 'title' => 'برای ریست کردن رمز عبور ایمیل خود را وارد کنید',
43 | 'send_pwd_reset' => 'ارسال لینک تغییر رمز عبور ',
44 | ],
45 |
46 | 'reset_password' => [
47 | 'title' => 'رمز عبور خود را دوبار تنظیم کنید',
48 | 'reset_pwd_btn' => 'تنظیم مجدد رمز عبور',
49 | ],
50 |
51 | 'confirm_passwords' => [
52 | 'title' => 'لطفا قبل از ادامه رمز خود را تأیید کنید.',
53 | 'forgot_your_password' => 'رمز عبور خود را فراموش کرده اید؟',
54 | ],
55 |
56 | 'verify_email' => [
57 | 'title' => 'آدرس ایمیل خود را تأیید کنید',
58 | 'success' => 'یک پیوند تأیید جدید به آدرس ایمیل شما ارسال شده است',
59 | 'notice' => 'قبل از ادامه ، لطفاً ایمیل خود را برای پیوند تأیید بررسی کنید. اگر ایمیل را دریافت نکردید ،',
60 | 'another_req' => 'برای درخواست مورد دیگر اینجا را کلیک کنید',
61 | ],
62 |
63 | 'emails' => [
64 | 'password' => [
65 | 'reset_link' => 'برای تغییر رمز عبور اینجا کلیک کنید',
66 | ],
67 | ],
68 | ];
69 |
--------------------------------------------------------------------------------
/locale/fa/crud.php:
--------------------------------------------------------------------------------
1 | 'اضافه',
6 | 'cancel' => 'لغو',
7 | 'create' => 'ایجاد',
8 | 'edit' => 'ویرایش',
9 | 'save' => 'ذخیره',
10 | 'detail' => 'جزئیات',
11 | 'back' => 'بازگشت',
12 | 'search' => 'جستجو',
13 | 'export' => 'استخراج',
14 | 'print' => 'چاپ',
15 | 'reset' => 'تنظیم مجدد',
16 | 'reload' => 'بارگیری مجدد',
17 | 'action' => 'عملیات',
18 | 'id' => 'شناسه',
19 | 'created_at' => 'ایجاد شده در',
20 | 'updated_at' => 'به روز شده در',
21 | 'deleted_at' => 'حذف شده در',
22 | 'are_you_sure' => 'آیا مطمئن هستید؟',
23 | ];
24 |
--------------------------------------------------------------------------------
/locale/fa/messages.php:
--------------------------------------------------------------------------------
1 | ':model با موفقیت بازیابی شد',
6 | 'saved' => ':model با موفقیت ذخیره شد.',
7 | 'updated' => ':model با موفقیت به روز شد.',
8 | 'deleted' => ':model با موفقیت حذف شد',
9 | 'not_found' => ':model پیدا نشد',
10 |
11 | ];
12 |
--------------------------------------------------------------------------------
/locale/id/auth.php:
--------------------------------------------------------------------------------
1 | 'Kredensial ini tidak cocok dengan catatan kami.',
17 | 'throttle' => 'Terlalu banyak upaya login. Silakan coba lagi dalam :detik detik.',
18 |
19 | 'full_name' => 'Nama lengkap',
20 | 'email' => 'Surel',
21 | 'password' => 'Kata sandi',
22 | 'confirm_password' => 'setujui password',
23 | 'remember_me' => 'Ingat saya',
24 | 'sign_in' => 'Masuk',
25 | 'sign_out' => 'Keluar',
26 | 'register' => 'Daftar',
27 |
28 | 'login' => [
29 | 'title' => 'Masuk untuk memulai sesi Anda',
30 | 'forgot_password' => 'Saya lupa kata sandi saya',
31 | 'register_membership' => 'Daftarkan keanggotaan baru',
32 | ],
33 |
34 | 'registration' => [
35 | 'title' => 'Daftarkan keanggotaan baru',
36 | 'i_agree' => 'saya setuju untuk',
37 | 'terms' => 'syarat-syaratnya',
38 | 'have_membership' => 'Saya sudah memiliki keanggotaan',
39 | ],
40 |
41 | 'forgot_password' => [
42 | 'title' => 'Masukkan Email untuk mengatur ulang kata sandi',
43 | 'send_pwd_reset' => 'Kirim Tautan Atur Ulang Kata Sandi',
44 | ],
45 |
46 | 'reset_password' => [
47 | 'title' => 'Mereset password Anda',
48 | 'reset_pwd_btn' => 'Setel Ulang Kata Sandi',
49 | ],
50 |
51 | 'confirm_passwords' => [
52 | 'title' => 'Harap konfirmasi kata sandi Anda sebelum melanjutkan.',
53 | 'forgot_your_password' => 'Lupa kata sandi Anda?',
54 | ],
55 |
56 | 'verify_email' => [
57 | 'title' => 'Verifikasi alamat email Anda',
58 | 'success' => 'Tautan verifikasi baru telah dikirim ke alamat email Anda',
59 | 'notice' => 'Sebelum melanjutkan, periksa email Anda untuk tautan verifikasi. Jika Anda tidak menerima email,',
60 | 'another_req' => 'klik di sini untuk meminta yang lain',
61 | ],
62 |
63 | 'emails' => [
64 | 'password' => [
65 | 'reset_link' => 'Klik di sini untuk mengatur ulang kata sandi Anda',
66 | ],
67 | ],
68 | ];
69 |
--------------------------------------------------------------------------------
/locale/id/crud.php:
--------------------------------------------------------------------------------
1 | 'Tambah baru',
6 | 'cancel' => 'Membatalkan',
7 | 'create' => 'Membuat',
8 | 'edit' => 'Sunting',
9 | 'save' => 'Menyimpan',
10 | 'detail' => 'Detail',
11 | 'back' => 'Kembali',
12 | 'search' => 'Mencari',
13 | 'export' => 'Ekspor',
14 | 'print' => 'Mencetak',
15 | 'reset' => 'Mengatur ulang',
16 | 'reload' => 'Muat ulang',
17 | 'action' => 'Tindakan',
18 | 'id' => 'Indo',
19 | 'created_at' => 'Dibuat di',
20 | 'updated_at' => 'Diperbarui Pada',
21 | 'deleted_at' => 'Dihapus At',
22 | 'are_you_sure' => 'Apa kamu yakin?',
23 | ];
24 |
--------------------------------------------------------------------------------
/locale/id/messages.php:
--------------------------------------------------------------------------------
1 | ':model berhasil diambil.',
5 | 'saved' => ':model berhasil disimpan.',
6 | 'updated' => ':model berhasil diperbarui.',
7 | 'deleted' => ':model berhasil dihapus.',
8 | 'not_found' => ':model tidak ditemukan',
9 | ];
10 |
--------------------------------------------------------------------------------
/locale/pl/auth.php:
--------------------------------------------------------------------------------
1 | 'Te dane uwierzytelniające nie pasują do naszych rekordów.',
17 | 'throttle' => 'Zbyt wiele prób logowania. Proszę spróbuj ponownie za :seconds sekund.',
18 |
19 | 'full_name' => 'Imię i Nazwisko',
20 | 'email' => 'Email',
21 | 'password' => 'Hasło',
22 | 'confirm_password' => 'Potwierdź Hasło',
23 | 'remember_me' => 'Zapamiętaj mnie',
24 | 'sign_in' => 'Zaloguj się',
25 | 'sign_out' => 'Wyloguj',
26 | 'register' => 'Zarejestruj się',
27 |
28 | 'login' => [
29 | 'title' => 'Zaloguj się, aby rozpocząć sesję',
30 | 'forgot_password' => 'Zapomniałem hasła',
31 | ],
32 |
33 | 'registration' => [
34 | 'title' => 'Zarejestruj nowe konto',
35 | 'i_agree' => 'Akceptuję',
36 | 'terms' => 'regulamin',
37 | 'have_membership' => 'Posiadam już konto',
38 | ],
39 |
40 | 'forgot_password' => [
41 | 'title' => 'Zapomniałeś hasła? Tutaj możesz łatwo odzyskać nowe hasło.',
42 | 'send_pwd_reset' => 'Wyślij link resetujący hasło',
43 | ],
44 |
45 | 'reset_password' => [
46 | 'title' => 'Został Ci tylko jeden krok do nowego hasła, odzyskaj je teraz.',
47 | 'reset_pwd_btn' => 'Resetuj Hasło',
48 | ],
49 |
50 | 'confirm_passwords' => [
51 | 'title' => 'Proszę potwierdź hasło przed kontynuacją.',
52 | 'forgot_your_password' => 'Zapomniałeś hasła?',
53 | ],
54 |
55 | 'verify_email' => [
56 | 'title' => 'Zweryfikuj swój adres email',
57 | 'success' => 'Na Twój adres email został wysłany świeży link weryfikacyjny.',
58 | 'notice' => 'Przed kontynuacją, sprawdź swój email w poszukiwaniu linka weryfikacyjnego. Jeśli nie otrzymałeś emaila,',
59 | 'another_req' => 'kliknij tutaj, aby poprosić o kolejny',
60 | ],
61 |
62 | 'emails' => [
63 | 'password' => [
64 | 'reset_link' => 'Kliknij tutaj, aby zresetować swoje hasło',
65 | ],
66 | ],
67 | ];
68 |
--------------------------------------------------------------------------------
/locale/pl/crud.php:
--------------------------------------------------------------------------------
1 | 'Dodaj Nowy',
5 | 'cancel' => 'Anuluj',
6 | 'create' => 'Utwórz',
7 | 'edit' => 'Edytuj',
8 | 'save' => 'Zapisz',
9 | 'delete' => 'Usuń',
10 | 'detail' => 'Szczegóły',
11 | 'back' => 'Powrót',
12 | 'search' => 'Szukaj',
13 | 'export' => 'Eksport',
14 | 'print' => 'Drukuj',
15 | 'reset' => 'Resetuj',
16 | 'reload' => 'Przeładuj',
17 | 'action' => 'Akcja',
18 | 'id' => 'Id',
19 | 'created_at' => 'Utworzono',
20 | 'updated_at' => 'Zaktualizowano',
21 | 'deleted_at' => 'Usunięto',
22 | 'are_you_sure' => 'Czy jesteś pewien?',
23 | ];
24 |
--------------------------------------------------------------------------------
/locale/pl/messages.php:
--------------------------------------------------------------------------------
1 | ':model został pomyślnie odzyskany.',
6 | 'saved' => ':model został pomyślnie zapisany.',
7 | 'updated' => ':model został pomyślnie zaktualizowany.',
8 | 'deleted' => ':model został pomyślnie usunięty.',
9 | 'not_found' => ':model nie został znaleziony.',
10 |
11 | ];
12 |
--------------------------------------------------------------------------------
/locale/zh_CN/auth.php:
--------------------------------------------------------------------------------
1 | '用户名或密码错误。',
16 | 'throttle' => '您尝试的登录次数过多,请 :seconds 秒后再试。',
17 | 'password' => '密码错误',
18 |
19 | 'full_name' => '姓名',
20 | 'email' => '邮箱',
21 | 'confirm_password' => '确认密码',
22 | 'remember_me' => '记住我',
23 | 'sign_in' => '登录',
24 | 'sign_out' => '退出',
25 | 'register' => '注册',
26 |
27 | 'login' => [
28 | 'title' => '登录以开始会话',
29 | 'forgot_password' => '忘记密码?',
30 | ],
31 |
32 | 'registration' => [
33 | 'title' => '创建新账号',
34 | 'i_agree' => '我同意',
35 | 'terms' => '条款',
36 | 'have_membership' => '已有账号',
37 | ],
38 |
39 | 'forgot_password' => [
40 | 'title' => '您忘记密码了吗?在这里可以重置您的密码。',
41 | 'send_pwd_reset' => '发送重置密码邮件',
42 | ],
43 |
44 | 'reset_password' => [
45 | 'title' => '您还差一步即可设置新密码,立即重置密码。',
46 | 'reset_pwd_btn' => '重置密码',
47 | ],
48 |
49 | 'confirm_passwords' => [
50 | 'title' => '在继续之前请确认您的密码。',
51 | 'forgot_your_password' => '忘记密码?',
52 | ],
53 |
54 | 'verify_email' => [
55 | 'title' => '验证您的邮箱',
56 | 'success' => '已重新发送验证邮件到您的邮箱',
57 | 'notice' => '在继续之前,请在邮箱查收验证邮件。如果您未收到,',
58 | 'another_req' => '点击这里重新发送',
59 | ],
60 |
61 | 'emails' => [
62 | 'password' => [
63 | 'reset_link' => '点击这里重置密码',
64 | ],
65 | ],
66 | ];
67 |
--------------------------------------------------------------------------------
/locale/zh_CN/crud.php:
--------------------------------------------------------------------------------
1 | '添加',
6 | 'cancel' => '取消',
7 | 'create' => '创建',
8 | 'edit' => '编辑',
9 | 'save' => '保存',
10 | 'delete' => '删除',
11 | 'detail' => '详情',
12 | 'back' => '返回',
13 | 'search' => '搜索',
14 | 'export' => '导出',
15 | 'print' => '打印',
16 | 'reset' => '重置',
17 | 'reload' => '刷新',
18 | 'action' => '操作',
19 | 'id' => 'ID',
20 | 'created_at' => '创建时间',
21 | 'updated_at' => '更新时间',
22 | 'deleted_at' => '删除时间',
23 | 'are_you_sure' => '您确定吗?',
24 | ];
25 |
--------------------------------------------------------------------------------
/locale/zh_CN/messages.php:
--------------------------------------------------------------------------------
1 | '成功获取:model。',
6 | 'saved' => '已成功创建:model。',
7 | 'updated' => '已成功修改:model。',
8 | 'deleted' => '已成功删除:model。',
9 | 'not_found' => '未找到:model。',
10 |
11 | ];
12 |
--------------------------------------------------------------------------------
/made-with-generator.md:
--------------------------------------------------------------------------------
1 | # Websites/Projects Made with InfyOm Laravel Generator
2 |
3 | List of Websites/Project using using InfyOm Laravel Generator.
4 | Comment on this [issue](https://github.com/InfyOmLabs/laravel-generator/issues/630) to get your project added here.
5 |
6 | - [InfyOm Blog](https://blog.infyom.com/)
7 | - [InfyTracker](http://labs.infyom.com/infy-tracker)
8 | - [Kavlinge Zoo](http://kavlingezoo.se/)
9 | - [TinkerTool](https://www.tinkertool.in/)
10 | - [Reantamchet](https://reantamchet.com/)
11 | - [Get Free Bitcoin](http://getfreebitco.in)
12 | - [InfyLMS](https://codecanyon.net/item/infylms-library-management-system-laravel-reactjs/24884824)
13 |
--------------------------------------------------------------------------------
/phpunit.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 | ./tests/
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/samples/fields_sample.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "name": "id",
4 | "dbType": "id",
5 | "htmlType": null,
6 | "validations": null,
7 | "searchable": false,
8 | "fillable": false,
9 | "primary": true,
10 | "inForm": false,
11 | "inIndex": false,
12 | "inView": false
13 | },
14 | {
15 | "name": "user_id",
16 | "dbType": "foreignId:constrained",
17 | "htmlType": "number",
18 | "relation": "mt1,User,user_id,id",
19 | "validations": "required|min:1",
20 | "searchable": false,
21 | "fillable": true,
22 | "primary": false,
23 | "inForm": true,
24 | "inIndex": true,
25 | "inView": true
26 | },
27 | {
28 | "name": "title",
29 | "dbType": "string",
30 | "htmlType": "text",
31 | "validations": "required",
32 | "searchable": true,
33 | "fillable": true,
34 | "primary": false,
35 | "inForm": true,
36 | "inIndex": true,
37 | "inView": true
38 | },
39 | {
40 | "name": "body",
41 | "dbType": "text",
42 | "htmlType": "textarea",
43 | "validations": "",
44 | "searchable": true,
45 | "fillable": true,
46 | "primary": false,
47 | "inForm": true,
48 | "inIndex": true,
49 | "inView": true
50 | },
51 | {
52 | "name": "is_featured",
53 | "dbType": "boolean",
54 | "htmlType": "boolean",
55 | "validations": "",
56 | "searchable": false,
57 | "fillable": true,
58 | "primary": false,
59 | "inForm": true,
60 | "inIndex": true,
61 | "inView": true
62 | },
63 | {
64 | "name": "is_enabled",
65 | "dbType": "boolean",
66 | "htmlType": "checkbox",
67 | "validations": "",
68 | "searchable": false,
69 | "fillable": true,
70 | "primary": false,
71 | "inForm": true,
72 | "inIndex": true,
73 | "inView": true
74 | },
75 | {
76 | "name": "published_at",
77 | "dbType": "date",
78 | "htmlType": "date",
79 | "validations": "",
80 | "searchable": false,
81 | "fillable": true,
82 | "primary": false,
83 | "inForm": true,
84 | "inIndex": true,
85 | "inView": true
86 | },
87 | {
88 | "name": "password",
89 | "dbType": "string",
90 | "htmlType": "password",
91 | "validations": "",
92 | "searchable": false,
93 | "fillable": true,
94 | "primary": false,
95 | "inForm": true,
96 | "inIndex": true,
97 | "inView": true
98 | },
99 | {
100 | "name": "post_type",
101 | "dbType": "integer",
102 | "htmlType": "radio:Blog:1,Event:2,Guest:3",
103 | "validations": "",
104 | "searchable": false,
105 | "fillable": true,
106 | "primary": false,
107 | "inForm": true,
108 | "inIndex": true,
109 | "inView": true
110 | },
111 | {
112 | "name": "status",
113 | "dbType": "integer",
114 | "htmlType": "select:Draft:1,Published:2,Archived:3",
115 | "validations": "",
116 | "searchable": false,
117 | "fillable": true,
118 | "primary": false,
119 | "inForm": true,
120 | "inIndex": true,
121 | "inView": true
122 | },
123 | {
124 | "name": "created_by",
125 | "dbType": "unsignedBigInteger:foreign,users,id",
126 | "htmlType": "number",
127 | "relation": "mt1,User,user_id,id",
128 | "validations": "required|min:1",
129 | "searchable": false,
130 | "fillable": true,
131 | "primary": false,
132 | "inForm": true,
133 | "inIndex": true,
134 | "inView": true
135 | },
136 | {
137 | "name": "created_at",
138 | "dbType": "timestamp",
139 | "htmlType": null,
140 | "validations": null,
141 | "searchable": false,
142 | "fillable": false,
143 | "primary": false,
144 | "inForm": false,
145 | "inIndex": false,
146 | "inView": true
147 | },
148 | {
149 | "name": "updated_at",
150 | "dbType": "timestamp",
151 | "htmlType": null,
152 | "validations": null,
153 | "searchable": false,
154 | "fillable": false,
155 | "primary": false,
156 | "inForm": false,
157 | "inIndex": false,
158 | "inView": true
159 | }
160 | ]
161 |
--------------------------------------------------------------------------------
/src/Commands/API/APIControllerGeneratorCommand.php:
--------------------------------------------------------------------------------
1 | generate();
31 |
32 | $this->performPostActions();
33 | }
34 |
35 | /**
36 | * Get the console command options.
37 | *
38 | * @return array
39 | */
40 | public function getOptions()
41 | {
42 | return array_merge(parent::getOptions(), []);
43 | }
44 |
45 | /**
46 | * Get the console command arguments.
47 | *
48 | * @return array
49 | */
50 | protected function getArguments()
51 | {
52 | return array_merge(parent::getArguments(), []);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/Commands/API/APIGeneratorCommand.php:
--------------------------------------------------------------------------------
1 | fireFileCreatingEvent('api');
27 |
28 | $this->generateCommonItems();
29 |
30 | $this->generateAPIItems();
31 |
32 | $this->performPostActionsWithMigration();
33 | $this->fireFileCreatedEvent('api');
34 | }
35 |
36 | /**
37 | * Get the console command options.
38 | *
39 | * @return array
40 | */
41 | public function getOptions()
42 | {
43 | return array_merge(parent::getOptions(), []);
44 | }
45 |
46 | /**
47 | * Get the console command arguments.
48 | *
49 | * @return array
50 | */
51 | protected function getArguments()
52 | {
53 | return array_merge(parent::getArguments(), []);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/Commands/API/APIRequestsGeneratorCommand.php:
--------------------------------------------------------------------------------
1 | generate();
31 |
32 | $this->performPostActions();
33 | }
34 |
35 | /**
36 | * Get the console command options.
37 | *
38 | * @return array
39 | */
40 | public function getOptions()
41 | {
42 | return array_merge(parent::getOptions(), []);
43 | }
44 |
45 | /**
46 | * Get the console command arguments.
47 | *
48 | * @return array
49 | */
50 | protected function getArguments()
51 | {
52 | return array_merge(parent::getArguments(), []);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/Commands/API/TestsGeneratorCommand.php:
--------------------------------------------------------------------------------
1 | generate();
32 |
33 | /** @var APITestGenerator $apiTestGenerator */
34 | $apiTestGenerator = app(APITestGenerator::class);
35 | $apiTestGenerator->generate();
36 |
37 | $this->performPostActions();
38 | }
39 |
40 | /**
41 | * Get the console command options.
42 | *
43 | * @return array
44 | */
45 | public function getOptions()
46 | {
47 | return array_merge(parent::getOptions(), []);
48 | }
49 |
50 | /**
51 | * Get the console command arguments.
52 | *
53 | * @return array
54 | */
55 | protected function getArguments()
56 | {
57 | return array_merge(parent::getArguments(), []);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/Commands/APIScaffoldGeneratorCommand.php:
--------------------------------------------------------------------------------
1 | fireFileCreatingEvent('api_scaffold');
30 |
31 | $this->generateCommonItems();
32 |
33 | $this->generateAPIItems();
34 |
35 | $this->generateScaffoldItems();
36 |
37 | $this->performPostActionsWithMigration();
38 | $this->fireFileCreatedEvent('api_scaffold');
39 | }
40 |
41 | /**
42 | * Get the console command options.
43 | *
44 | * @return array
45 | */
46 | public function getOptions()
47 | {
48 | return array_merge(parent::getOptions(), []);
49 | }
50 |
51 | /**
52 | * Get the console command arguments.
53 | *
54 | * @return array
55 | */
56 | protected function getArguments()
57 | {
58 | return array_merge(parent::getArguments(), []);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/Commands/Common/MigrationGeneratorCommand.php:
--------------------------------------------------------------------------------
1 | option('fromTable')) {
29 | $this->error('fromTable option is not allowed to use with migration generator');
30 |
31 | return;
32 | }
33 |
34 | /** @var MigrationGenerator $migrationGenerator */
35 | $migrationGenerator = app(MigrationGenerator::class);
36 | $migrationGenerator->generate();
37 |
38 | $this->performPostActionsWithMigration();
39 | }
40 |
41 | /**
42 | * Get the console command options.
43 | *
44 | * @return array
45 | */
46 | public function getOptions()
47 | {
48 | return array_merge(parent::getOptions(), []);
49 | }
50 |
51 | /**
52 | * Get the console command arguments.
53 | *
54 | * @return array
55 | */
56 | protected function getArguments()
57 | {
58 | return array_merge(parent::getArguments(), []);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/Commands/Common/ModelGeneratorCommand.php:
--------------------------------------------------------------------------------
1 | generate();
31 |
32 | $this->performPostActions();
33 | }
34 |
35 | /**
36 | * Get the console command options.
37 | *
38 | * @return array
39 | */
40 | public function getOptions()
41 | {
42 | return array_merge(parent::getOptions(), []);
43 | }
44 |
45 | /**
46 | * Get the console command arguments.
47 | *
48 | * @return array
49 | */
50 | protected function getArguments()
51 | {
52 | return array_merge(parent::getArguments(), []);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/Commands/Common/RepositoryGeneratorCommand.php:
--------------------------------------------------------------------------------
1 | generate();
31 |
32 | $this->performPostActions();
33 | }
34 |
35 | /**
36 | * Get the console command options.
37 | *
38 | * @return array
39 | */
40 | public function getOptions()
41 | {
42 | return array_merge(parent::getOptions(), []);
43 | }
44 |
45 | /**
46 | * Get the console command arguments.
47 | *
48 | * @return array
49 | */
50 | protected function getArguments()
51 | {
52 | return array_merge(parent::getArguments(), []);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/Commands/Publish/GeneratorPublishCommand.php:
--------------------------------------------------------------------------------
1 | updateRouteServiceProvider();
26 | $this->publishTestCases();
27 | $this->publishBaseController();
28 | $repositoryPattern = config('laravel_generator.options.repository_pattern', true);
29 | if ($repositoryPattern) {
30 | $this->publishBaseRepository();
31 | }
32 | if ($this->option('localized')) {
33 | $this->publishLocaleFiles();
34 | }
35 | }
36 |
37 | private function updateRouteServiceProvider()
38 | {
39 | $routeServiceProviderPath = app_path('Providers'.DIRECTORY_SEPARATOR.'RouteServiceProvider.php');
40 |
41 | if (!file_exists($routeServiceProviderPath)) {
42 | $this->error("Route Service provider not found on $routeServiceProviderPath");
43 |
44 | return;
45 | }
46 |
47 | $fileContent = g_filesystem()->getFile($routeServiceProviderPath);
48 |
49 | $search = "Route::middleware('api')".infy_nl().str(' ')->repeat(16)."->prefix('api')";
50 | $beforeContent = str($fileContent)->before($search);
51 | $afterContent = str($fileContent)->after($search);
52 |
53 | $finalContent = $beforeContent.$search.infy_nl().str(' ')->repeat(16)."->as('api.')".$afterContent;
54 | g_filesystem()->createFile($routeServiceProviderPath, $finalContent);
55 | }
56 |
57 | private function publishTestCases()
58 | {
59 | $testsPath = config('laravel_generator.path.tests', base_path('tests/'));
60 | $testsNameSpace = config('laravel_generator.namespace.tests', 'Tests');
61 | $createdAtField = config('laravel_generator.timestamps.created_at', 'created_at');
62 | $updatedAtField = config('laravel_generator.timestamps.updated_at', 'updated_at');
63 |
64 | $templateData = view('laravel-generator::api.test.api_test_trait', [
65 | 'timestamps' => "['$createdAtField', '$updatedAtField']",
66 | 'namespacesTests' => $testsNameSpace,
67 | ])->render();
68 |
69 | $fileName = 'ApiTestTrait.php';
70 |
71 | if (file_exists($testsPath.$fileName) && !$this->confirmOverwrite($fileName)) {
72 | return;
73 | }
74 |
75 | g_filesystem()->createFile($testsPath.$fileName, $templateData);
76 | $this->info('ApiTestTrait created');
77 |
78 | $testAPIsPath = config('laravel_generator.path.api_test', base_path('tests/APIs/'));
79 | if (!file_exists($testAPIsPath)) {
80 | g_filesystem()->createDirectoryIfNotExist($testAPIsPath);
81 | $this->info('APIs Tests directory created');
82 | }
83 |
84 | $testRepositoriesPath = config('laravel_generator.path.repository_test', base_path('tests/Repositories/'));
85 | if (!file_exists($testRepositoriesPath)) {
86 | g_filesystem()->createDirectoryIfNotExist($testRepositoriesPath);
87 | $this->info('Repositories Tests directory created');
88 | }
89 | }
90 |
91 | private function publishBaseController()
92 | {
93 | $controllerPath = app_path('Http/Controllers/');
94 | $fileName = 'AppBaseController.php';
95 |
96 | if (file_exists($controllerPath.$fileName) && !$this->confirmOverwrite($fileName)) {
97 | return;
98 | }
99 |
100 | $templateData = view('laravel-generator::stubs.app_base_controller', [
101 | 'namespaceApp' => $this->getLaravel()->getNamespace(),
102 | 'apiPrefix' => config('laravel_generator.api_prefix'),
103 | ])->render();
104 |
105 | g_filesystem()->createFile($controllerPath.$fileName, $templateData);
106 |
107 | $this->info('AppBaseController created');
108 | }
109 |
110 | private function publishBaseRepository()
111 | {
112 | $repositoryPath = app_path('Repositories/');
113 |
114 | $fileName = 'BaseRepository.php';
115 |
116 | if (file_exists($repositoryPath.$fileName) && !$this->confirmOverwrite($fileName)) {
117 | return;
118 | }
119 |
120 | g_filesystem()->createDirectoryIfNotExist($repositoryPath);
121 |
122 | $templateData = view('laravel-generator::stubs.base_repository', [
123 | 'namespaceApp' => $this->getLaravel()->getNamespace(),
124 | ])->render();
125 |
126 | g_filesystem()->createFile($repositoryPath.$fileName, $templateData);
127 |
128 | $this->info('BaseRepository created');
129 | }
130 |
131 | private function publishLocaleFiles()
132 | {
133 | $localesDir = __DIR__.'/../../../locale/';
134 |
135 | $this->publishDirectory($localesDir, lang_path(), 'lang', true);
136 |
137 | $this->comment('Locale files published');
138 | }
139 |
140 | /**
141 | * Get the console command options.
142 | *
143 | * @return array
144 | */
145 | public function getOptions()
146 | {
147 | return [
148 | ['localized', null, InputOption::VALUE_NONE, 'Localize files.'],
149 | ];
150 | }
151 |
152 | /**
153 | * Get the console command arguments.
154 | *
155 | * @return array
156 | */
157 | protected function getArguments()
158 | {
159 | return [];
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/src/Commands/Publish/PublishBaseCommand.php:
--------------------------------------------------------------------------------
1 | confirmOverwrite($destinationFile)) {
18 | return;
19 | }
20 |
21 | copy($sourceFile, $destinationFile);
22 |
23 | $this->comment($fileName.' published');
24 | $this->info($destinationFile);
25 | }
26 |
27 | public function publishDirectory(string $sourceDir, string $destinationDir, string $dirName, bool $force = false): bool
28 | {
29 | if (file_exists($destinationDir) && !$force && !$this->confirmOverwrite($destinationDir)) {
30 | return false;
31 | }
32 |
33 | File::makeDirectory($destinationDir, 493, true, true);
34 | File::copyDirectory($sourceDir, $destinationDir);
35 |
36 | $this->comment($dirName.' published');
37 | $this->info($destinationDir);
38 |
39 | return true;
40 | }
41 |
42 | protected function confirmOverwrite(string $fileName, string $prompt = ''): bool
43 | {
44 | $prompt = (empty($prompt))
45 | ? $fileName.' already exists. Do you want to overwrite it? [y|N]'
46 | : $prompt;
47 |
48 | return $this->confirm($prompt, false);
49 | }
50 |
51 | /**
52 | * Get the console command options.
53 | *
54 | * @return array
55 | */
56 | public function getOptions()
57 | {
58 | return [];
59 | }
60 |
61 | /**
62 | * Get the console command arguments.
63 | *
64 | * @return array
65 | */
66 | protected function getArguments()
67 | {
68 | return [];
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/Commands/Publish/PublishTablesCommand.php:
--------------------------------------------------------------------------------
1 | argument('type');
28 |
29 | if ($tableType === 'datatable') {
30 | $this->publishDataTableViews();
31 |
32 | return;
33 | }
34 |
35 | if ($tableType === 'livewire') {
36 | $this->publishLivewireTableViews();
37 |
38 | return;
39 | }
40 |
41 | throw new Exception('Invalid Table Type');
42 | }
43 |
44 | public function publishLivewireTableViews()
45 | {
46 | $viewsPath = config('laravel_generator.path.views', resource_path('views/'));
47 | $templateType = config('laravel_generator.templates', 'adminlte-templates');
48 | $files = [
49 | 'templates.scaffold.table.livewire.actions' => 'common/livewire-tables/actions.blade.php',
50 | ];
51 |
52 | g_filesystem()->createDirectoryIfNotExist($viewsPath.'common/livewire-tables');
53 |
54 | /** @var Factory $viewFactory */
55 | $viewFactory = view();
56 | foreach ($files as $templateView => $destinationView) {
57 | $templateViewPath = $viewFactory->getFinder()->find($templateType.'::'.$templateView);
58 | $content = g_filesystem()->getFile($templateViewPath);
59 | $destinationFile = $viewsPath.$destinationView;
60 | g_filesystem()->createFile($destinationFile, $content);
61 | }
62 | }
63 |
64 | protected function publishDataTableViews()
65 | {
66 | $viewsPath = config('laravel_generator.path.views', resource_path('views/'));
67 |
68 | $files = [
69 | 'layouts.datatables_css' => 'layouts/datatables_css.blade.php',
70 | 'layouts.datatables_js' => 'layouts/datatables_js.blade.php',
71 | ];
72 |
73 | foreach ($files as $templateView => $destinationView) {
74 | $content = view('laravel-generator::scaffold.'.$templateView)->render();
75 | $destinationFile = $viewsPath.$destinationView;
76 | g_filesystem()->createFile($destinationFile, $content);
77 | }
78 | }
79 |
80 | /**
81 | * Get the console command arguments.
82 | *
83 | * @return array
84 | */
85 | public function getArguments()
86 | {
87 | return [
88 | ['type', InputArgument::REQUIRED, 'Types of Tables (datatable / livewire)'],
89 | ];
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/src/Commands/RollbackGeneratorCommand.php:
--------------------------------------------------------------------------------
1 | config = app(GeneratorConfig::class);
34 | $this->config->setCommand($this);
35 | $this->config->init();
36 |
37 | $type = $this->argument('type');
38 | if (!in_array($type, ['api', 'scaffold', 'api_scaffold'])) {
39 | $this->error('Invalid rollback type');
40 |
41 | return 1;
42 | }
43 |
44 | $this->fireFileDeletingEvent($type);
45 | $views = $this->option('views');
46 | if (!empty($views)) {
47 | $views = explode(',', $views);
48 | $viewGenerator = new ViewGenerator();
49 | $viewGenerator->rollback($views);
50 |
51 | $this->info('Generating autoload files');
52 | $this->composer->dumpOptimized();
53 | $this->fireFileDeletedEvent($type);
54 |
55 | return 0;
56 | }
57 |
58 | $migrationGenerator = app(MigrationGenerator::class);
59 | $migrationGenerator->rollback();
60 |
61 | $modelGenerator = app(ModelGenerator::class);
62 | $modelGenerator->rollback();
63 |
64 | if ($this->config->options->repositoryPattern) {
65 | $repositoryGenerator = app(RepositoryGenerator::class);
66 | $repositoryGenerator->rollback();
67 | }
68 |
69 | if (in_array($type, ['api', 'api_scaffold'])) {
70 | $requestGenerator = app(APIRequestGenerator::class);
71 | $requestGenerator->rollback();
72 |
73 | $controllerGenerator = app(APIControllerGenerator::class);
74 | $controllerGenerator->rollback();
75 |
76 | $routesGenerator = app(APIRoutesGenerator::class);
77 | $routesGenerator->rollback();
78 | }
79 |
80 | if (in_array($type, ['scaffold', 'api_scaffold'])) {
81 | $requestGenerator = app(RequestGenerator::class);
82 | $requestGenerator->rollback();
83 |
84 | $controllerGenerator = app(ControllerGenerator::class);
85 | $controllerGenerator->rollback();
86 |
87 | $viewGenerator = app(ViewGenerator::class);
88 | $viewGenerator->rollback();
89 |
90 | $routeGenerator = app(RoutesGenerator::class);
91 | $routeGenerator->rollback();
92 |
93 | $menuGenerator = app(MenuGenerator::class);
94 | $menuGenerator->rollback();
95 | }
96 |
97 | if ($this->config->options->tests) {
98 | $repositoryTestGenerator = app(RepositoryTestGenerator::class);
99 | $repositoryTestGenerator->rollback();
100 |
101 | $apiTestGenerator = app(APITestGenerator::class);
102 | $apiTestGenerator->rollback();
103 | }
104 |
105 | if ($this->config->options->factory or $this->config->options->tests) {
106 | $factoryGenerator = app(FactoryGenerator::class);
107 | $factoryGenerator->rollback();
108 | }
109 |
110 | if ($this->config->options->seeder) {
111 | $seederGenerator = app(SeederGenerator::class);
112 | $seederGenerator->rollback();
113 | }
114 |
115 | $this->info('Generating autoload files');
116 | $this->composer->dumpOptimized();
117 |
118 | $this->fireFileDeletedEvent($type);
119 |
120 | return 0;
121 | }
122 |
123 | /**
124 | * Get the console command arguments.
125 | *
126 | * @return array
127 | */
128 | protected function getArguments()
129 | {
130 | return [
131 | ['model', InputArgument::REQUIRED, 'Singular Model name'],
132 | ['type', InputArgument::REQUIRED, 'Rollback type: (api / scaffold / api_scaffold)'],
133 | ];
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/src/Commands/Scaffold/ControllerGeneratorCommand.php:
--------------------------------------------------------------------------------
1 | generate();
31 |
32 | $this->performPostActions();
33 | }
34 |
35 | /**
36 | * Get the console command options.
37 | *
38 | * @return array
39 | */
40 | public function getOptions()
41 | {
42 | return array_merge(parent::getOptions(), []);
43 | }
44 |
45 | /**
46 | * Get the console command arguments.
47 | *
48 | * @return array
49 | */
50 | protected function getArguments()
51 | {
52 | return array_merge(parent::getArguments(), []);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/Commands/Scaffold/RequestsGeneratorCommand.php:
--------------------------------------------------------------------------------
1 | generate();
31 |
32 | $this->performPostActions();
33 | }
34 |
35 | /**
36 | * Get the console command options.
37 | *
38 | * @return array
39 | */
40 | public function getOptions()
41 | {
42 | return array_merge(parent::getOptions(), []);
43 | }
44 |
45 | /**
46 | * Get the console command arguments.
47 | *
48 | * @return array
49 | */
50 | protected function getArguments()
51 | {
52 | return array_merge(parent::getArguments(), []);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/Commands/Scaffold/ScaffoldGeneratorCommand.php:
--------------------------------------------------------------------------------
1 | checkIsThereAnyDataToGenerate()) {
28 | $this->fireFileCreatingEvent('scaffold');
29 | $this->generateCommonItems();
30 |
31 | $this->generateScaffoldItems();
32 |
33 | $this->performPostActionsWithMigration();
34 | $this->fireFileCreatedEvent('scaffold');
35 | } else {
36 | $this->config->commandInfo('There are not enough input fields for scaffold generation.');
37 | }
38 | }
39 |
40 | /**
41 | * Get the console command options.
42 | *
43 | * @return array
44 | */
45 | public function getOptions()
46 | {
47 | return array_merge(parent::getOptions(), []);
48 | }
49 |
50 | /**
51 | * Get the console command arguments.
52 | *
53 | * @return array
54 | */
55 | protected function getArguments()
56 | {
57 | return array_merge(parent::getArguments(), []);
58 | }
59 |
60 | protected function checkIsThereAnyDataToGenerate(): bool
61 | {
62 | if (count($this->config->fields) > 1) {
63 | return true;
64 | }
65 |
66 | return false;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/Commands/Scaffold/ViewsGeneratorCommand.php:
--------------------------------------------------------------------------------
1 | generate();
31 |
32 | $this->performPostActions();
33 | }
34 |
35 | /**
36 | * Get the console command options.
37 | *
38 | * @return array
39 | */
40 | public function getOptions()
41 | {
42 | return array_merge(parent::getOptions(), []);
43 | }
44 |
45 | /**
46 | * Get the console command arguments.
47 | *
48 | * @return array
49 | */
50 | protected function getArguments()
51 | {
52 | return array_merge(parent::getArguments(), []);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/Common/FileSystem.php:
--------------------------------------------------------------------------------
1 | type = array_shift($inputs);
19 | $modelWithRelation = explode(':', array_shift($inputs)); //e.g ModelName:relationName
20 | if (count($modelWithRelation) == 2) {
21 | $relation->relationName = $modelWithRelation[1];
22 | unset($modelWithRelation[1]);
23 | }
24 | $relation->inputs = array_merge($modelWithRelation, $inputs);
25 |
26 | return $relation;
27 | }
28 |
29 | public function getRelationFunctionText(string $relationText = null): string
30 | {
31 | $singularRelation = (!empty($this->relationName)) ? $this->relationName : Str::camel($relationText);
32 | $pluralRelation = (!empty($this->relationName)) ? $this->relationName : Str::camel(Str::plural($relationText));
33 |
34 | switch ($this->type) {
35 | case '1t1':
36 | $functionName = $singularRelation;
37 | $relation = 'hasOne';
38 | $relationClass = 'HasOne';
39 | break;
40 | case '1tm':
41 | $functionName = $pluralRelation;
42 | $relation = 'hasMany';
43 | $relationClass = 'HasMany';
44 | break;
45 | case 'mt1':
46 | if (!empty($this->relationName)) {
47 | $singularRelation = $this->relationName;
48 | } elseif (isset($this->inputs[1])) {
49 | $singularRelation = Str::camel(str_replace('_id', '', strtolower($this->inputs[1])));
50 | }
51 | $functionName = $singularRelation;
52 | $relation = 'belongsTo';
53 | $relationClass = 'BelongsTo';
54 | break;
55 | case 'mtm':
56 | $functionName = $pluralRelation;
57 | $relation = 'belongsToMany';
58 | $relationClass = 'BelongsToMany';
59 | break;
60 | case 'hmt':
61 | $functionName = $pluralRelation;
62 | $relation = 'hasManyThrough';
63 | $relationClass = 'HasManyThrough';
64 | break;
65 | default:
66 | $functionName = '';
67 | $relation = '';
68 | $relationClass = '';
69 | break;
70 | }
71 |
72 | if (!empty($functionName) and !empty($relation)) {
73 | return $this->generateRelation($functionName, $relation, $relationClass);
74 | }
75 |
76 | return '';
77 | }
78 |
79 | protected function generateRelation($functionName, $relation, $relationClass)
80 | {
81 | $inputs = $this->inputs;
82 | $relatedModelName = array_shift($inputs);
83 |
84 | if (count($inputs) > 0) {
85 | $inputFields = implode("', '", $inputs);
86 | $inputFields = ", '".$inputFields."'";
87 | } else {
88 | $inputFields = '';
89 | }
90 |
91 | return view('laravel-generator::model.relationship', [
92 | 'relationClass' => $relationClass,
93 | 'functionName' => $functionName,
94 | 'relation' => $relation,
95 | 'relatedModel' => $relatedModelName,
96 | 'fields' => $inputFields,
97 | ])->render();
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/src/Criteria/LimitOffsetCriteria.php:
--------------------------------------------------------------------------------
1 | request = $request;
18 | }
19 |
20 | /**
21 | * Apply criteria in query repository.
22 | *
23 | * @param $model
24 | * @param \Prettus\Repository\Contracts\RepositoryInterface $repository
25 | *
26 | * @return mixed
27 | */
28 | public function apply($model, \Prettus\Repository\Contracts\RepositoryInterface $repository)
29 | {
30 | $limit = (int) $this->request->get('limit', null);
31 | $offset = (int) $this->request->get('offset', null);
32 |
33 | if ($limit) {
34 | $model = $model->limit($limit);
35 | }
36 |
37 | if ($offset && $limit) {
38 | $model = $model->skip($offset);
39 | }
40 |
41 | return $model;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/DTOs/GeneratorNamespaces.php:
--------------------------------------------------------------------------------
1 | route) {
16 | return $this->route.$append;
17 | }
18 |
19 | return '';
20 | }
21 |
22 | public function getViewPrefixWith($append)
23 | {
24 | if ($this->view) {
25 | return $this->view.$append;
26 | }
27 |
28 | return '';
29 | }
30 |
31 | public function getViewPrefixForInclude()
32 | {
33 | if ($this->view) {
34 | return Str::replace('/', '.', $this->view).'.';
35 | }
36 |
37 | return '';
38 | }
39 |
40 | public function mergeRoutePrefix(array $prefixes)
41 | {
42 | foreach ($prefixes as $prefix) {
43 | if (empty($prefix)) {
44 | continue;
45 | }
46 |
47 | $this->route .= '.'.Str::camel($prefix);
48 | }
49 |
50 | $this->route = ltrim($this->route, '.');
51 | }
52 |
53 | public function mergeNamespacePrefix(array $prefixes)
54 | {
55 | foreach ($prefixes as $prefix) {
56 | if (empty($prefix)) {
57 | continue;
58 | }
59 |
60 | $this->namespace .= '\\'.Str::title($prefix);
61 | }
62 |
63 | $this->namespace = ltrim($this->namespace, '\\');
64 | }
65 |
66 | public function mergeViewPrefix(array $prefixes)
67 | {
68 | foreach ($prefixes as $prefix) {
69 | if (empty($prefix)) {
70 | continue;
71 | }
72 |
73 | $this->view .= '/'.Str::snake($prefix);
74 | }
75 |
76 | $this->view = ltrim($this->view, '/');
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/DTOs/ModelNames.php:
--------------------------------------------------------------------------------
1 | type = $type;
18 | $this->data = $data;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Events/GeneratorFileCreating.php:
--------------------------------------------------------------------------------
1 | type = $type;
18 | $this->data = $data;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Events/GeneratorFileDeleted.php:
--------------------------------------------------------------------------------
1 | type = $type;
18 | $this->data = $data;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Events/GeneratorFileDeleting.php:
--------------------------------------------------------------------------------
1 | type = $type;
18 | $this->data = $data;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Facades/FileUtils.php:
--------------------------------------------------------------------------------
1 | '',
21 | 'createFile' => true,
22 | 'createDirectoryIfNotExist' => true,
23 | 'deleteFile' => true,
24 | ];
25 | }
26 |
27 | static::swap($fake = Mockery::mock()->allows($allowedMethods));
28 |
29 | return $fake;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Generators/API/APIControllerGenerator.php:
--------------------------------------------------------------------------------
1 | path = $this->config->paths->apiController;
17 | $this->fileName = $this->config->modelNames->name.'APIController.php';
18 | }
19 |
20 | public function variables(): array
21 | {
22 | return array_merge([], $this->docsVariables());
23 | }
24 |
25 | public function getViewName(): string
26 | {
27 | if ($this->config->options->repositoryPattern) {
28 | $templateName = 'repository.controller';
29 | } else {
30 | $templateName = 'model.controller';
31 | }
32 |
33 | if ($this->config->options->resources) {
34 | $templateName .= '_resource';
35 | }
36 |
37 | return $templateName;
38 | }
39 |
40 | public function generate()
41 | {
42 | $viewName = $this->getViewName();
43 |
44 | $templateData = view('laravel-generator::api.controller.'.$viewName, $this->variables())->render();
45 |
46 | g_filesystem()->createFile($this->path.$this->fileName, $templateData);
47 |
48 | $this->config->commandComment(infy_nl().'API Controller created: ');
49 | $this->config->commandInfo($this->fileName);
50 | }
51 |
52 | protected function docsVariables(): array
53 | {
54 | $methods = ['controller', 'index', 'store', 'show', 'update', 'destroy'];
55 |
56 | if ($this->config->options->swagger) {
57 | $templatePrefix = 'controller';
58 | $templateType = 'swagger-generator';
59 | } else {
60 | $templatePrefix = 'api.docs.controller';
61 | $templateType = 'laravel-generator';
62 | }
63 |
64 | $variables = [];
65 | foreach ($methods as $method) {
66 | $variable = 'doc'.Str::title($method);
67 | $variables[$variable] = view($templateType.'::'.$templatePrefix.'.'.$method)->render();
68 | }
69 |
70 | return $variables;
71 | }
72 |
73 | public function rollback()
74 | {
75 | if ($this->rollbackFile($this->path, $this->fileName)) {
76 | $this->config->commandComment('API Controller file deleted: '.$this->fileName);
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/Generators/API/APIRequestGenerator.php:
--------------------------------------------------------------------------------
1 | path = $this->config->paths->apiRequest;
19 | $this->createFileName = 'Create'.$this->config->modelNames->name.'APIRequest.php';
20 | $this->updateFileName = 'Update'.$this->config->modelNames->name.'APIRequest.php';
21 | }
22 |
23 | public function generate()
24 | {
25 | $this->generateCreateRequest();
26 | $this->generateUpdateRequest();
27 | }
28 |
29 | protected function generateCreateRequest()
30 | {
31 | $templateData = view('laravel-generator::api.request.create', $this->variables())->render();
32 |
33 | g_filesystem()->createFile($this->path.$this->createFileName, $templateData);
34 |
35 | $this->config->commandComment(infy_nl().'Create Request created: ');
36 | $this->config->commandInfo($this->createFileName);
37 | }
38 |
39 | protected function generateUpdateRequest()
40 | {
41 | $modelGenerator = app(ModelGenerator::class);
42 | $rules = $modelGenerator->generateUniqueRules();
43 |
44 | $templateData = view('laravel-generator::api.request.update', [
45 | 'uniqueRules' => $rules,
46 | ])->render();
47 |
48 | g_filesystem()->createFile($this->path.$this->updateFileName, $templateData);
49 |
50 | $this->config->commandComment(infy_nl().'Update Request created: ');
51 | $this->config->commandInfo($this->updateFileName);
52 | }
53 |
54 | public function rollback()
55 | {
56 | if ($this->rollbackFile($this->path, $this->createFileName)) {
57 | $this->config->commandComment('Create API Request file deleted: '.$this->createFileName);
58 | }
59 |
60 | if ($this->rollbackFile($this->path, $this->updateFileName)) {
61 | $this->config->commandComment('Update API Request file deleted: '.$this->updateFileName);
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/Generators/API/APIResourceGenerator.php:
--------------------------------------------------------------------------------
1 | path = $this->config->paths->apiResource;
16 | $this->fileName = $this->config->modelNames->name.'Resource.php';
17 | }
18 |
19 | public function variables(): array
20 | {
21 | return [
22 | 'fields' => implode(','.infy_nl_tab(1, 3), $this->generateResourceFields()),
23 | ];
24 | }
25 |
26 | public function generate()
27 | {
28 | $templateData = view('laravel-generator::api.resource.resource', $this->variables())->render();
29 |
30 | g_filesystem()->createFile($this->path.$this->fileName, $templateData);
31 |
32 | $this->config->commandComment(infy_nl().'API Resource created: ');
33 | $this->config->commandInfo($this->fileName);
34 | }
35 |
36 | protected function generateResourceFields(): array
37 | {
38 | $resourceFields = [];
39 | foreach ($this->config->fields as $field) {
40 | $resourceFields[] = "'".$field->name."' => \$this->".$field->name;
41 | }
42 |
43 | return $resourceFields;
44 | }
45 |
46 | public function rollback()
47 | {
48 | if ($this->rollbackFile($this->path, $this->fileName)) {
49 | $this->config->commandComment('API Resource file deleted: '.$this->fileName);
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/Generators/API/APIRoutesGenerator.php:
--------------------------------------------------------------------------------
1 | path = $this->config->paths->apiRoutes;
15 | }
16 |
17 | public function generate()
18 | {
19 | $routeContents = g_filesystem()->getFile($this->path);
20 |
21 | $routes = view('laravel-generator::api.routes', $this->variables())->render();
22 |
23 | if (Str::contains($routeContents, $routes)) {
24 | $this->config->commandInfo(infy_nl().'Menu '.$this->config->modelNames->dashedPlural.' already exists, Skipping Adjustment.');
25 |
26 | return;
27 | }
28 |
29 | $routeContents .= infy_nls(2).$routes;
30 |
31 | g_filesystem()->createFile($this->path, $routeContents);
32 |
33 | $this->config->commandComment(infy_nl().$this->config->modelNames->dashedPlural.' api routes added.');
34 | }
35 |
36 | public function rollback()
37 | {
38 | $routeContents = g_filesystem()->getFile($this->path);
39 |
40 | $routes = view('laravel-generator::api.routes', $this->variables())->render();
41 |
42 | if (Str::contains($routeContents, $routes)) {
43 | $routeContents = str_replace($routes, '', $routeContents);
44 | g_filesystem()->createFile($this->path, $routeContents);
45 | $this->config->commandComment('api routes deleted');
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/Generators/API/APITestGenerator.php:
--------------------------------------------------------------------------------
1 | path = $this->config->paths->apiTests;
16 | $this->fileName = $this->config->modelNames->name.'ApiTest.php';
17 | }
18 |
19 | public function generate()
20 | {
21 | $templateData = view('laravel-generator::api.test.api_test', $this->variables())->render();
22 |
23 | g_filesystem()->createFile($this->path.$this->fileName, $templateData);
24 |
25 | $this->config->commandComment(infy_nl().'ApiTest created: ');
26 | $this->config->commandInfo($this->fileName);
27 | }
28 |
29 | public function rollback()
30 | {
31 | if ($this->rollbackFile($this->path, $this->fileName)) {
32 | $this->config->commandComment('API Test file deleted: '.$this->fileName);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Generators/BaseGenerator.php:
--------------------------------------------------------------------------------
1 | config = app(GeneratorConfig::class);
16 | }
17 |
18 | public function rollbackFile($path, $fileName): bool
19 | {
20 | if (file_exists($path.$fileName)) {
21 | return g_filesystem()->deleteFile($path, $fileName);
22 | }
23 |
24 | return false;
25 | }
26 |
27 | public function variables(): array
28 | {
29 | return [];
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Generators/MigrationGenerator.php:
--------------------------------------------------------------------------------
1 | path = config('laravel_generator.path.migration', database_path('migrations/'));
16 | }
17 |
18 | public function generate()
19 | {
20 | $templateData = view('laravel-generator::migration', $this->variables())->render();
21 |
22 | $fileName = date('Y_m_d_His').'_'.'create_'.strtolower($this->config->tableName).'_table.php';
23 |
24 | g_filesystem()->createFile($this->path.$fileName, $templateData);
25 |
26 | $this->config->commandComment(infy_nl().'Migration created: ');
27 | $this->config->commandInfo($fileName);
28 | }
29 |
30 | public function variables(): array
31 | {
32 | return [
33 | 'fields' => $this->generateFields(),
34 | ];
35 | }
36 |
37 | protected function generateFields(): string
38 | {
39 | $fields = [];
40 | $foreignKeys = [];
41 | $createdAtField = null;
42 | $updatedAtField = null;
43 |
44 | if (isset($this->config->fields) && !empty($this->config->fields)) {
45 | foreach ($this->config->fields as $field) {
46 | if ($field->name == 'created_at') {
47 | $createdAtField = $field;
48 | continue;
49 | } else {
50 | if ($field->name == 'updated_at') {
51 | $updatedAtField = $field;
52 | continue;
53 | }
54 | }
55 |
56 | $fields[] = $field->migrationText;
57 | if (!empty($field->foreignKeyText)) {
58 | $foreignKeys[] = $field->foreignKeyText;
59 | }
60 | }
61 | }
62 |
63 | if ($createdAtField->name ?? '' === 'created_at' and $updatedAtField->name ?? '' === 'updated_at') {
64 | $fields[] = '$table->timestamps();';
65 | } else {
66 | if ($createdAtField) {
67 | $fields[] = $createdAtField->migrationText;
68 | }
69 | if ($updatedAtField) {
70 | $fields[] = $updatedAtField->migrationText;
71 | }
72 | }
73 |
74 | if ($this->config->options->softDelete) {
75 | $softDeleteFieldName = config('laravel_generator.timestamps.deleted_at', 'deleted_at');
76 | if ($softDeleteFieldName === 'deleted_at') {
77 | $fields[] = '$table->softDeletes();';
78 | } else {
79 | $fields[] = '$table->softDeletes(\''.$softDeleteFieldName.'\');';
80 | }
81 | }
82 |
83 | return implode(infy_nl_tab(1, 3), array_merge($fields, $foreignKeys));
84 | }
85 |
86 | public function rollback()
87 | {
88 | $fileName = 'create_'.$this->config->tableName.'_table.php';
89 |
90 | /** @var SplFileInfo $allFiles */
91 | $allFiles = File::allFiles($this->path);
92 |
93 | $files = [];
94 |
95 | if (!empty($allFiles)) {
96 | foreach ($allFiles as $file) {
97 | $files[] = $file->getFilename();
98 | }
99 |
100 | $files = array_reverse($files);
101 |
102 | foreach ($files as $file) {
103 | if (Str::contains($file, $fileName)) {
104 | if ($this->rollbackFile($this->path, $file)) {
105 | $this->config->commandComment('Migration file deleted: '.$file);
106 | }
107 | break;
108 | }
109 | }
110 | }
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/src/Generators/RepositoryGenerator.php:
--------------------------------------------------------------------------------
1 | path = $this->config->paths->repository;
14 | $this->fileName = $this->config->modelNames->name.'Repository.php';
15 | }
16 |
17 | public function variables(): array
18 | {
19 | return [
20 | 'fieldSearchable' => $this->getSearchableFields(),
21 | ];
22 | }
23 |
24 | public function generate()
25 | {
26 | $templateData = view('laravel-generator::repository.repository', $this->variables())->render();
27 |
28 | g_filesystem()->createFile($this->path.$this->fileName, $templateData);
29 |
30 | $this->config->commandComment(infy_nl().'Repository created: ');
31 | $this->config->commandInfo($this->fileName);
32 | }
33 |
34 | protected function getSearchableFields()
35 | {
36 | $searchables = [];
37 |
38 | foreach ($this->config->fields as $field) {
39 | if ($field->isSearchable) {
40 | $searchables[] = "'".$field->name."'";
41 | }
42 | }
43 |
44 | return implode(','.infy_nl_tab(1, 2), $searchables);
45 | }
46 |
47 | public function rollback()
48 | {
49 | if ($this->rollbackFile($this->path, $this->fileName)) {
50 | $this->config->commandComment('Repository file deleted: '.$this->fileName);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/Generators/RepositoryTestGenerator.php:
--------------------------------------------------------------------------------
1 | path = config('laravel_generator.path.repository_test', base_path('tests/Repositories/'));
14 | $this->fileName = $this->config->modelNames->name.'RepositoryTest.php';
15 | }
16 |
17 | public function generate()
18 | {
19 | $templateData = view('laravel-generator::repository.repository_test', $this->variables())->render();
20 |
21 | g_filesystem()->createFile($this->path.$this->fileName, $templateData);
22 |
23 | $this->config->commandComment(infy_nl().'RepositoryTest created: ');
24 | $this->config->commandInfo($this->fileName);
25 | }
26 |
27 | public function rollback()
28 | {
29 | if ($this->rollbackFile($this->path, $this->fileName)) {
30 | $this->config->commandComment('Repository Test file deleted: '.$this->fileName);
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Generators/Scaffold/ControllerGenerator.php:
--------------------------------------------------------------------------------
1 | path = $this->config->paths->controller;
19 | $this->templateType = config('laravel_generator.templates', 'adminlte-templates');
20 | $this->fileName = $this->config->modelNames->name.'Controller.php';
21 | }
22 |
23 | public function generate()
24 | {
25 | $variables = [];
26 |
27 | switch ($this->config->tableType) {
28 | case 'blade':
29 | if ($this->config->options->repositoryPattern) {
30 | $indexMethodView = 'index_method_repository';
31 | } else {
32 | $indexMethodView = 'index_method';
33 | }
34 | $variables['renderType'] = 'paginate(10)';
35 | break;
36 |
37 | case 'datatables':
38 | $indexMethodView = 'index_method_datatable';
39 | $this->generateDataTable();
40 | break;
41 |
42 | case 'livewire':
43 | $indexMethodView = 'index_method_livewire';
44 | $this->generateLivewireTable();
45 | break;
46 |
47 | default:
48 | throw new Exception('Invalid Table Type');
49 | }
50 |
51 | if ($this->config->options->repositoryPattern) {
52 | $viewName = 'controller_repository';
53 | } else {
54 | $viewName = 'controller';
55 | }
56 |
57 | $variables['indexMethod'] = view('laravel-generator::scaffold.controller.'.$indexMethodView, $variables)
58 | ->render();
59 |
60 | $templateData = view('laravel-generator::scaffold.controller.'.$viewName, $variables)->render();
61 |
62 | g_filesystem()->createFile($this->path.$this->fileName, $templateData);
63 |
64 | $this->config->commandComment(infy_nl().'Controller created: ');
65 | $this->config->commandInfo($this->fileName);
66 | }
67 |
68 | protected function generateDataTable()
69 | {
70 | $templateData = view('laravel-generator::scaffold.table.datatable', [
71 | 'columns' => implode(','.infy_nl_tab(1, 3), $this->generateDataTableColumns()),
72 | ])->render();
73 |
74 | $path = $this->config->paths->dataTables;
75 |
76 | $fileName = $this->config->modelNames->name.'DataTable.php';
77 |
78 | g_filesystem()->createFile($path.$fileName, $templateData);
79 |
80 | $this->config->commandComment(infy_nl().'DataTable created: ');
81 | $this->config->commandInfo($fileName);
82 | }
83 |
84 | protected function generateLivewireTable()
85 | {
86 | $templateData = view('laravel-generator::scaffold.table.livewire', [
87 | 'columns' => implode(','.infy_nl_tab(1, 3), $this->generateLivewireTableColumns()),
88 | ])->render();
89 |
90 | $path = $this->config->paths->livewireTables;
91 |
92 | $fileName = $this->config->modelNames->plural.'Table.php';
93 |
94 | g_filesystem()->createFile($path.$fileName, $templateData);
95 |
96 | $this->config->commandComment(infy_nl().'LivewireTable created: ');
97 | $this->config->commandInfo($fileName);
98 | }
99 |
100 | protected function generateDataTableColumns(): array
101 | {
102 | $dataTableColumns = [];
103 | foreach ($this->config->fields as $field) {
104 | if (!$field->inIndex) {
105 | continue;
106 | }
107 |
108 | $dataTableColumns[] = trim(view(
109 | $this->templateType.'::templates.scaffold.table.datatable.column',
110 | $field->variables()
111 | )->render());
112 | }
113 |
114 | return $dataTableColumns;
115 | }
116 |
117 | protected function generateLivewireTableColumns(): array
118 | {
119 | $livewireTableColumns = [];
120 |
121 | foreach ($this->config->fields as $field) {
122 | if (!$field->inIndex) {
123 | continue;
124 | }
125 |
126 | $fieldTemplate = 'Column::make("'.$field->getTitle().'", "'.$field->name.'")'.infy_nl();
127 | $fieldTemplate .= infy_tabs(4).'->sortable()';
128 |
129 | if ($field->isSearchable) {
130 | $fieldTemplate .= infy_nl().infy_tabs(4).'->searchable()';
131 | }
132 |
133 | $livewireTableColumns[] = $fieldTemplate;
134 | }
135 |
136 | return $livewireTableColumns;
137 | }
138 |
139 | public function rollback()
140 | {
141 | if ($this->rollbackFile($this->path, $this->fileName)) {
142 | $this->config->commandComment('Controller file deleted: '.$this->fileName);
143 | }
144 |
145 | if ($this->config->tableType === 'datatables') {
146 | if ($this->rollbackFile(
147 | $this->config->paths->dataTables,
148 | $this->config->modelNames->name.'DataTable.php'
149 | )) {
150 | $this->config->commandComment('DataTable file deleted: '.$this->fileName);
151 | }
152 | }
153 |
154 | if ($this->config->tableType === 'livewire') {
155 | if ($this->rollbackFile(
156 | $this->config->paths->livewireTables,
157 | $this->config->modelNames->plural.'Table.php'
158 | )) {
159 | $this->config->commandComment('Livewire Table file deleted: '.$this->fileName);
160 | }
161 | }
162 | }
163 | }
164 |
--------------------------------------------------------------------------------
/src/Generators/Scaffold/MenuGenerator.php:
--------------------------------------------------------------------------------
1 | path = config('laravel_generator.path.menu_file', resource_path('views/layouts/menu.blade.php'));
17 | $this->templateType = config('laravel_generator.templates', 'adminlte-templates');
18 | }
19 |
20 | public function generate()
21 | {
22 | $menuContents = g_filesystem()->getFile($this->path);
23 |
24 | $menu = view($this->templateType.'::templates.layouts.menu_template')->render();
25 |
26 | if (Str::contains($menuContents, $menu)) {
27 | $this->config->commandInfo(infy_nl().'Menu '.$this->config->modelNames->humanPlural.' already exists, Skipping Adjustment.');
28 |
29 | return;
30 | }
31 |
32 | $menuContents .= infy_nl().$menu;
33 |
34 | g_filesystem()->createFile($this->path, $menuContents);
35 | $this->config->commandComment(infy_nl().$this->config->modelNames->dashedPlural.' menu added.');
36 | }
37 |
38 | public function rollback()
39 | {
40 | $menuContents = g_filesystem()->getFile($this->path);
41 |
42 | $menu = view($this->templateType.'::templates.layouts.menu_template')->render();
43 |
44 | if (Str::contains($menuContents, $menu)) {
45 | g_filesystem()->createFile($this->path, str_replace($menu, '', $menuContents));
46 | $this->config->commandComment('menu deleted');
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/Generators/Scaffold/RequestGenerator.php:
--------------------------------------------------------------------------------
1 | path = $this->config->paths->request;
19 | $this->createFileName = 'Create'.$this->config->modelNames->name.'Request.php';
20 | $this->updateFileName = 'Update'.$this->config->modelNames->name.'Request.php';
21 | }
22 |
23 | public function generate()
24 | {
25 | $this->generateCreateRequest();
26 | $this->generateUpdateRequest();
27 | }
28 |
29 | protected function generateCreateRequest()
30 | {
31 | $templateData = view('laravel-generator::scaffold.request.create', $this->variables())->render();
32 |
33 | g_filesystem()->createFile($this->path.$this->createFileName, $templateData);
34 |
35 | $this->config->commandComment(infy_nl().'Create Request created: ');
36 | $this->config->commandInfo($this->createFileName);
37 | }
38 |
39 | protected function generateUpdateRequest()
40 | {
41 | $modelGenerator = new ModelGenerator();
42 | $rules = $modelGenerator->generateUniqueRules();
43 |
44 | $templateData = view('laravel-generator::scaffold.request.update', [
45 | 'uniqueRules' => $rules,
46 | ])->render();
47 |
48 | g_filesystem()->createFile($this->path.$this->updateFileName, $templateData);
49 |
50 | $this->config->commandComment(infy_nl().'Update Request created: ');
51 | $this->config->commandInfo($this->updateFileName);
52 | }
53 |
54 | public function rollback()
55 | {
56 | if ($this->rollbackFile($this->path, $this->createFileName)) {
57 | $this->config->commandComment('Create Request file deleted: '.$this->createFileName);
58 | }
59 |
60 | if ($this->rollbackFile($this->path, $this->updateFileName)) {
61 | $this->config->commandComment('Update Request file deleted: '.$this->updateFileName);
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/Generators/Scaffold/RoutesGenerator.php:
--------------------------------------------------------------------------------
1 | path = $this->config->paths->routes;
15 | }
16 |
17 | public function generate()
18 | {
19 | $routeContents = g_filesystem()->getFile($this->path);
20 |
21 | $routes = view('laravel-generator::scaffold.routes')->render();
22 |
23 | if (Str::contains($routeContents, $routes)) {
24 | $this->config->commandInfo(infy_nl().'Route '.$this->config->modelNames->dashedPlural.' already exists, Skipping Adjustment.');
25 |
26 | return;
27 | }
28 |
29 | $routeContents .= infy_nl().$routes;
30 |
31 | g_filesystem()->createFile($this->path, $routeContents);
32 | $this->config->commandComment(infy_nl().$this->config->modelNames->dashedPlural.' routes added.');
33 | }
34 |
35 | public function rollback()
36 | {
37 | $routeContents = g_filesystem()->getFile($this->path);
38 |
39 | $routes = view('laravel-generator::scaffold.routes')->render();
40 |
41 | if (Str::contains($routeContents, $routes)) {
42 | $routeContents = str_replace($routes, '', $routeContents);
43 | g_filesystem()->createFile($this->path, $routeContents);
44 | $this->config->commandComment('scaffold routes deleted');
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/Generators/SeederGenerator.php:
--------------------------------------------------------------------------------
1 | path = $this->config->paths->seeder;
14 | $this->fileName = $this->config->modelNames->plural.'TableSeeder.php';
15 | }
16 |
17 | public function generate()
18 | {
19 | $templateData = view('laravel-generator::model.seeder', $this->variables())->render();
20 |
21 | g_filesystem()->createFile($this->path.$this->fileName, $templateData);
22 |
23 | $this->config->commandComment(infy_nl().'Seeder created: ');
24 | $this->config->commandInfo($this->fileName);
25 | }
26 |
27 | public function rollback()
28 | {
29 | if ($this->rollbackFile($this->path, $this->fileName)) {
30 | $this->config->commandComment('Seeder file deleted: '.$this->fileName);
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Generators/SwaggerGenerator.php:
--------------------------------------------------------------------------------
1 | dbType);
16 |
17 | if (empty($fieldData['fieldType'])) {
18 | continue;
19 | }
20 |
21 | $fieldTypes[] = [
22 | 'fieldName' => $field->name,
23 | 'type' => $fieldData['fieldType'],
24 | 'format' => $fieldData['fieldFormat'],
25 | 'nullable' => !$field->isNotNull ? 'true' : 'false',
26 | 'readOnly' => !$field->isFillable ? 'true' : 'false',
27 | 'description' => (!empty($field->description)) ? $field->description : '',
28 | ];
29 | }
30 |
31 | return $fieldTypes;
32 | }
33 |
34 | public static function getFieldType($type): array
35 | {
36 | $fieldType = null;
37 | $fieldFormat = null;
38 | switch (strtolower($type)) {
39 | case 'increments':
40 | case 'integer':
41 | case 'unsignedinteger':
42 | case 'smallinteger':
43 | case 'long':
44 | case 'biginteger':
45 | case 'unsignedbiginteger':
46 | $fieldType = 'integer';
47 | $fieldFormat = 'int32';
48 | break;
49 | case 'double':
50 | case 'float':
51 | case 'real':
52 | case 'decimal':
53 | $fieldType = 'number';
54 | $fieldFormat = 'number';
55 | break;
56 | case 'boolean':
57 | $fieldType = 'boolean';
58 | break;
59 | case 'string':
60 | case 'char':
61 | case 'text':
62 | case 'mediumtext':
63 | case 'longtext':
64 | case 'enum':
65 | $fieldType = 'string';
66 | break;
67 | case 'byte':
68 | $fieldType = 'string';
69 | $fieldFormat = 'byte';
70 | break;
71 | case 'binary':
72 | $fieldType = 'string';
73 | $fieldFormat = 'binary';
74 | break;
75 | case 'password':
76 | $fieldType = 'string';
77 | $fieldFormat = 'password';
78 | break;
79 | case 'date':
80 | $fieldType = 'string';
81 | $fieldFormat = 'date';
82 | break;
83 | case 'datetime':
84 | case 'timestamp':
85 | $fieldType = 'string';
86 | $fieldFormat = 'date-time';
87 | break;
88 | }
89 |
90 | return ['fieldType' => $fieldType, 'fieldFormat' => $fieldFormat];
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/Generators/ViewServiceProviderGenerator.php:
--------------------------------------------------------------------------------
1 | config->paths->viewProvider;
17 |
18 | $fileName = basename($destination);
19 |
20 | if (File::exists($destination)) {
21 | return;
22 | }
23 | File::copy($templateData, $destination);
24 |
25 | $this->config->commandComment($fileName.' published');
26 | $this->config->commandInfo($fileName);
27 | }
28 |
29 | /**
30 | * @param string $views
31 | * @param string $variableName
32 | * @param string $columns
33 | * @param string $tableName
34 | * @param string|null $modelName
35 | */
36 | public function addViewVariables($views, $variableName, $columns, $tableName, $modelName = null)
37 | {
38 | if (!empty($modelName)) {
39 | $model = $modelName;
40 | } else {
41 | $model = model_name_from_table_name($tableName);
42 | }
43 |
44 | $this->config->addDynamicVariable('$COMPOSER_VIEWS$', $views);
45 | $this->config->addDynamicVariable('$COMPOSER_VIEW_VARIABLE$', $variableName);
46 | $this->config->addDynamicVariable(
47 | '$COMPOSER_VIEW_VARIABLE_VALUES$',
48 | $model."::pluck($columns)->toArray()"
49 | );
50 |
51 | $mainViewContent = $this->addViewComposer();
52 | $mainViewContent = $this->addNamespace($model, $mainViewContent);
53 | $this->addCustomProvider();
54 |
55 | g_filesystem()->createFile($this->config->paths->viewProvider, $mainViewContent);
56 | $this->config->commandComment('View service provider file updated.');
57 | }
58 |
59 | public function addViewComposer(): string
60 | {
61 | $mainViewContent = g_filesystem()->getFile($this->config->paths->viewProvider);
62 | $newViewStatement = get_template('scaffold.view_composer', 'laravel-generator');
63 | $newViewStatement = fill_template($this->config->dynamicVars, $newViewStatement);
64 |
65 | $newViewStatement = infy_nl().$newViewStatement;
66 | preg_match_all('/public function boot(.*)/', $mainViewContent, $matches);
67 |
68 | $totalMatches = count($matches[0]);
69 | $lastSeederStatement = $matches[0][$totalMatches - 1];
70 |
71 | $replacePosition = strpos($mainViewContent, $lastSeederStatement);
72 |
73 | return substr_replace(
74 | $mainViewContent,
75 | $newViewStatement,
76 | $replacePosition + strlen($lastSeederStatement) + 6,
77 | 0
78 | );
79 | }
80 |
81 | public function addCustomProvider()
82 | {
83 | $configFile = base_path().'/config/app.php';
84 | $file = g_filesystem()->getFile($configFile);
85 | $searchFor = 'Illuminate\View\ViewServiceProvider::class,';
86 | $customProviders = strpos($file, $searchFor);
87 |
88 | $isExist = strpos($file, "App\Providers\ViewServiceProvider::class");
89 | if ($customProviders && !$isExist) {
90 | $newChanges = substr_replace(
91 | $file,
92 | infy_nl().infy_tab(8).'\App\Providers\ViewServiceProvider::class,',
93 | $customProviders + strlen($searchFor),
94 | 0
95 | );
96 | g_filesystem()->createFile($configFile, $newChanges);
97 | }
98 | }
99 |
100 | public function addNamespace($model, $mainViewContent)
101 | {
102 | $newModelStatement = 'use '.$this->config->namespaces->model.'\\'.$model.';';
103 | $isNameSpaceExist = strpos($mainViewContent, $newModelStatement);
104 | $newModelStatement = infy_nl().$newModelStatement;
105 | if (!$isNameSpaceExist) {
106 | preg_match_all('/namespace(.*)/', $mainViewContent, $matches);
107 | $totalMatches = count($matches[0]);
108 | $nameSpaceStatement = $matches[0][$totalMatches - 1];
109 | $replacePosition = strpos($mainViewContent, $nameSpaceStatement);
110 | $mainViewContent = substr_replace(
111 | $mainViewContent,
112 | $newModelStatement,
113 | $replacePosition + strlen($nameSpaceStatement),
114 | 0
115 | );
116 | }
117 |
118 | return $mainViewContent;
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/src/Request/APIRequest.php:
--------------------------------------------------------------------------------
1 | json(ResponseUtil::makeError($messages), Response::HTTP_BAD_REQUEST);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Utils/GeneratorFieldsInputUtil.php:
--------------------------------------------------------------------------------
1 | 0) {
25 | foreach ($arr as $key => $item) {
26 | $arrStr .= "'$item' => '$key', ";
27 | }
28 | $arrStr = substr($arrStr, 0, strlen($arrStr) - 2);
29 | }
30 |
31 | $arrStr .= ']';
32 |
33 | return $arrStr;
34 | }
35 |
36 | /**
37 | * Prepare string of array.
38 | */
39 | public static function prepareValuesArrayStr(array $arr): string
40 | {
41 | $arrStr = '[';
42 | if (count($arr) > 0) {
43 | foreach ($arr as $item) {
44 | $arrStr .= "'$item', ";
45 | }
46 | $arrStr = substr($arrStr, 0, strlen($arrStr) - 2);
47 | }
48 |
49 | $arrStr .= ']';
50 |
51 | return $arrStr;
52 | }
53 |
54 | public static function prepareKeyValueArrFromLabelValueStr($values): array
55 | {
56 | $arr = [];
57 | if (count($values) > 0) {
58 | foreach ($values as $value) {
59 | $labelValue = explode(':', $value);
60 |
61 | if (count($labelValue) > 1) {
62 | $arr[$labelValue[0]] = $labelValue[1];
63 | } else {
64 | $arr[$labelValue[0]] = $labelValue[0];
65 | }
66 | }
67 | }
68 |
69 | return $arr;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/Utils/HTMLFieldGenerator.php:
--------------------------------------------------------------------------------
1 | htmlType;
13 | $variables = [];
14 |
15 | if (!empty($validations = self::generateValidations($field))) {
16 | $variables['options'] = ', '.implode(', ', $validations);
17 | }
18 |
19 | switch ($field->htmlType) {
20 | case 'select':
21 | case 'enum':
22 | $viewName = 'select';
23 | $keyValues = GeneratorFieldsInputUtil::prepareKeyValueArrFromLabelValueStr($field->htmlValues);
24 |
25 | $variables = [
26 | 'selectValues' => GeneratorFieldsInputUtil::prepareKeyValueArrayStr($keyValues),
27 | ];
28 | break;
29 | case 'checkbox':
30 | if (count($field->htmlValues) > 0) {
31 | $checkboxValue = $field->htmlValues[0];
32 | } else {
33 | $checkboxValue = 1;
34 | }
35 | $variables['checkboxVal'] = $checkboxValue;
36 | break;
37 | case 'radio':
38 | $keyValues = GeneratorFieldsInputUtil::prepareKeyValueArrFromLabelValueStr($field->htmlValues);
39 |
40 | $radioButtons = [];
41 | foreach ($keyValues as $label => $value) {
42 | $radioButtons[] = view($templateType.'.fields.radio', [
43 | 'label' => $label,
44 | 'value' => $value,
45 | 'fieldName' => $field->name,
46 | ]);
47 | }
48 |
49 | return view($templateType.'.fields.radio_group', array_merge(
50 | ['radioButtons' => implode(infy_nl_tab(), $radioButtons)],
51 | array_merge(
52 | $field->variables(),
53 | $variables
54 | )
55 | ))->render();
56 | }
57 |
58 | return view(
59 | $templateType.'.fields.'.$viewName,
60 | array_merge(
61 | $field->variables(),
62 | $variables
63 | )
64 | )->render();
65 | }
66 |
67 | public static function generateValidations(GeneratorField $field)
68 | {
69 | $validations = explode('|', $field->validations);
70 | $validationRules = [];
71 |
72 | foreach ($validations as $validation) {
73 | if ($validation === 'required') {
74 | $validationRules[] = "'required'";
75 | continue;
76 | }
77 |
78 | if (!Str::contains($validation, ['max:', 'min:'])) {
79 | continue;
80 | }
81 |
82 | $validationText = substr($validation, 0, 3);
83 | $sizeInNumber = substr($validation, 4);
84 |
85 | $sizeText = ($validationText == 'min') ? 'minlength' : 'maxlength';
86 | if ($field->htmlType == 'number') {
87 | $sizeText = $validationText;
88 | }
89 |
90 | $size = "'$sizeText' => $sizeInNumber";
91 | $validationRules[] = $size;
92 | }
93 |
94 | return $validationRules;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/Utils/ResponseUtil.php:
--------------------------------------------------------------------------------
1 | true,
11 | 'data' => $data,
12 | 'message' => $message,
13 | ];
14 | }
15 |
16 | public static function makeError(string $message, array $data = []): array
17 | {
18 | $res = [
19 | 'success' => false,
20 | 'message' => $message,
21 | ];
22 |
23 | if (!empty($data)) {
24 | $res['data'] = $data;
25 | }
26 |
27 | return $res;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Utils/SchemaUtil.php:
--------------------------------------------------------------------------------
1 | '.$fieldType."('".$fieldName."'";
18 |
19 | if (count($fieldTypeParams) > 0) {
20 | $fieldStr .= ', '.implode(' ,', $fieldTypeParams);
21 | }
22 | if ($fieldType == 'enum') {
23 | $inputsArr = explode(',', $field['htmlTypeInputs']);
24 | $inputArrStr = GeneratorFieldsInputUtil::prepareValuesArrayStr($inputsArr);
25 | $fieldStr .= ', '.$inputArrStr;
26 | }
27 |
28 | $fieldStr .= ')';
29 |
30 | if (count($databaseInputs) > 0) {
31 | foreach ($databaseInputs as $databaseInput) {
32 | $databaseInput = explode(',', $databaseInput);
33 | $type = array_shift($databaseInput);
34 | $fieldStr .= "->$type(".implode(',', $databaseInput).')';
35 | }
36 | }
37 |
38 | $fieldStr .= ';';
39 |
40 | return $fieldStr;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/helpers.php:
--------------------------------------------------------------------------------
1 | '$name.index'",
63 | "'store' => '$name.store'",
64 | "'show' => '$name.show'",
65 | "'update' => '$name.update'",
66 | "'destroy' => '$name.destroy'",
67 | ];
68 |
69 | if ($isScaffold) {
70 | $result[] = "'create' => '$name.create'";
71 | $result[] = "'edit' => '$name.edit'";
72 | }
73 |
74 | return $result;
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/tests/Commands/APIGeneratorCommandTest.php:
--------------------------------------------------------------------------------
1 | set('laravel_generator.options.seeder', true);
57 | config()->set('laravel_generator.options.repository_pattern', false);
58 |
59 | artisan(APIGeneratorCommand::class, ['model' => 'Post'])
60 | ->expectsQuestion('Field: (name db_type html_type options)', 'title body text')
61 | ->expectsQuestion('Enter validations: ', 'required')
62 | ->expectsQuestion('Field: (name db_type html_type options)', 'exit')
63 | ->expectsQuestion(PHP_EOL.'Do you want to migrate database? [y|N]', false)
64 | ->assertSuccessful();
65 | });
66 |
67 | it('generates all files for api from fields file', function () {
68 | $fileUtils = FileUtils::fake([
69 | 'createFile' => true,
70 | 'createDirectoryIfNotExist' => true,
71 | 'deleteFile' => true,
72 | ]);
73 |
74 | $shouldHaveCalledGenerators = [
75 | MigrationGenerator::class,
76 | ModelGenerator::class,
77 | RepositoryGenerator::class,
78 | APIRequestGenerator::class,
79 | APIControllerGenerator::class,
80 | APIRoutesGenerator::class,
81 | ];
82 |
83 | mockShouldHaveCalledGenerateMethod($shouldHaveCalledGenerators);
84 |
85 | $shouldNotHaveCalledGenerator = [
86 | RequestGenerator::class,
87 | ControllerGenerator::class,
88 | ViewGenerator::class,
89 | RoutesGenerator::class,
90 | MenuGenerator::class,
91 | RepositoryTestGenerator::class,
92 | APITestGenerator::class,
93 | FactoryGenerator::class,
94 | SeederGenerator::class,
95 | ];
96 |
97 | mockShouldNotHaveCalledGenerateMethod($shouldNotHaveCalledGenerator);
98 |
99 | $modelSchemaFile = __DIR__.'/../fixtures/model_schema/Post.json';
100 |
101 | $fileUtils->shouldReceive('getFile')
102 | ->withArgs([$modelSchemaFile])
103 | ->andReturn(file_get_contents($modelSchemaFile));
104 | $fileUtils->shouldReceive('getFile')
105 | ->andReturn('');
106 |
107 | artisan(APIGeneratorCommand::class, ['model' => 'Post', '--fieldsFile' => $modelSchemaFile])
108 | ->expectsQuestion(PHP_EOL.'Do you want to migrate database? [y|N]', false)
109 | ->assertSuccessful();
110 | });
111 |
--------------------------------------------------------------------------------
/tests/Commands/APIScaffoldGeneratorCommandTest.php:
--------------------------------------------------------------------------------
1 | set('laravel_generator.options.seeder', true);
57 |
58 | artisan(APIScaffoldGeneratorCommand::class, ['model' => 'Post'])
59 | ->expectsQuestion('Field: (name db_type html_type options)', 'title body text')
60 | ->expectsQuestion('Enter validations: ', 'required')
61 | ->expectsQuestion('Field: (name db_type html_type options)', 'exit')
62 | ->expectsQuestion(PHP_EOL.'Do you want to migrate database? [y|N]', false)
63 | ->assertSuccessful();
64 | });
65 |
66 | it('generates all files for api_scaffold from fields file', function () {
67 | $fileUtils = FileUtils::fake([
68 | 'createFile' => true,
69 | 'createDirectoryIfNotExist' => true,
70 | 'deleteFile' => true,
71 | ]);
72 |
73 | $shouldHaveCalledGenerators = [
74 | MigrationGenerator::class,
75 | ModelGenerator::class,
76 | RepositoryGenerator::class,
77 | APIRequestGenerator::class,
78 | APIControllerGenerator::class,
79 | APIRoutesGenerator::class,
80 | RequestGenerator::class,
81 | ControllerGenerator::class,
82 | ViewGenerator::class,
83 | RoutesGenerator::class,
84 | MenuGenerator::class,
85 | RepositoryTestGenerator::class,
86 | APITestGenerator::class,
87 | FactoryGenerator::class,
88 | ];
89 |
90 | mockShouldHaveCalledGenerateMethod($shouldHaveCalledGenerators);
91 |
92 | $shouldNotHaveCalledGenerator = [
93 | SeederGenerator::class,
94 | ];
95 |
96 | mockShouldNotHaveCalledGenerateMethod($shouldNotHaveCalledGenerator);
97 |
98 | config()->set('laravel_generator.options.tests', true);
99 |
100 | $modelSchemaFile = __DIR__.'/../fixtures/model_schema/Post.json';
101 |
102 | $fileUtils->shouldReceive('getFile')
103 | ->withArgs([$modelSchemaFile])
104 | ->andReturn(file_get_contents($modelSchemaFile));
105 | $fileUtils->shouldReceive('getFile')
106 | ->andReturn('');
107 |
108 | artisan(APIScaffoldGeneratorCommand::class, ['model' => 'Post', '--fieldsFile' => $modelSchemaFile])
109 | ->expectsQuestion(PHP_EOL.'Do you want to migrate database? [y|N]', false)
110 | ->assertSuccessful();
111 | });
112 |
--------------------------------------------------------------------------------
/tests/Commands/PublishTablesCommandTest.php:
--------------------------------------------------------------------------------
1 | 'invalid']);
9 | })->throws(Exception::class, 'Invalid Table Type');
10 |
--------------------------------------------------------------------------------
/tests/Commands/RollbackGeneratorCommandTest.php:
--------------------------------------------------------------------------------
1 | 'User', 'type' => 'random'])
29 | ->assertExitCode(1);
30 | });
31 |
32 | function mockShouldHaveCalledRollbackGenerator(array $shouldHaveCalledGenerators): array
33 | {
34 | $mockedObjects = [];
35 |
36 | foreach ($shouldHaveCalledGenerators as $generator) {
37 | $mock = m::mock($generator);
38 |
39 | $mock->shouldReceive('rollback')
40 | ->once()
41 | ->andReturn(true);
42 |
43 | app()->singleton($generator, function () use ($mock) {
44 | return $mock;
45 | });
46 |
47 | $mockedObjects[] = $mock;
48 | }
49 |
50 | return $mockedObjects;
51 | }
52 |
53 | function mockShouldNotHaveCalledRollbackGenerators(array $shouldNotHaveCalledGenerator): array
54 | {
55 | $mockedObjects = [];
56 |
57 | foreach ($shouldNotHaveCalledGenerator as $generator) {
58 | $mock = m::mock($generator);
59 |
60 | $mock->shouldNotReceive('rollback');
61 |
62 | app()->singleton($generator, function () use ($mock) {
63 | return $mock;
64 | });
65 |
66 | $mockedObjects[] = $mock;
67 | }
68 |
69 | return $mockedObjects;
70 | }
71 |
72 | it('validates that all files are rolled back for api_scaffold', function () {
73 | $shouldHaveCalledGenerators = [
74 | MigrationGenerator::class,
75 | ModelGenerator::class,
76 | RepositoryGenerator::class,
77 | APIRequestGenerator::class,
78 | APIControllerGenerator::class,
79 | APIRoutesGenerator::class,
80 | RequestGenerator::class,
81 | ControllerGenerator::class,
82 | ViewGenerator::class,
83 | RoutesGenerator::class,
84 | MenuGenerator::class,
85 | FactoryGenerator::class,
86 | RepositoryTestGenerator::class,
87 | APITestGenerator::class,
88 | ];
89 |
90 | mockShouldHaveCalledRollbackGenerator($shouldHaveCalledGenerators);
91 |
92 | $shouldNotHaveCalledGenerator = [
93 | SeederGenerator::class,
94 | ];
95 |
96 | mockShouldNotHaveCalledRollbackGenerators($shouldNotHaveCalledGenerator);
97 |
98 | config()->set('laravel_generator.options.tests', true);
99 |
100 | artisan(RollbackGeneratorCommand::class, ['model' => 'User', 'type' => 'api_scaffold']);
101 | });
102 |
103 | it('validates that all files are rolled back for api', function () {
104 | $shouldHaveCalledGenerators = [
105 | MigrationGenerator::class,
106 | ModelGenerator::class,
107 | APIRequestGenerator::class,
108 | APIControllerGenerator::class,
109 | APIRoutesGenerator::class,
110 | FactoryGenerator::class,
111 | SeederGenerator::class,
112 | ];
113 |
114 | mockShouldHaveCalledRollbackGenerator($shouldHaveCalledGenerators);
115 |
116 | $shouldNotHaveCalledGenerator = [
117 | RepositoryGenerator::class,
118 | RequestGenerator::class,
119 | ControllerGenerator::class,
120 | ViewGenerator::class,
121 | RoutesGenerator::class,
122 | MenuGenerator::class,
123 | ];
124 |
125 | mockShouldNotHaveCalledRollbackGenerators($shouldNotHaveCalledGenerator);
126 |
127 | config()->set('laravel_generator.options.repository_pattern', false);
128 | config()->set('laravel_generator.options.factory', true);
129 | config()->set('laravel_generator.options.seeder', true);
130 |
131 | artisan(RollbackGeneratorCommand::class, ['model' => 'User', 'type' => 'api']);
132 | });
133 |
134 | it('validates that all files are rolled back for scaffold', function () {
135 | $shouldHaveCalledGenerators = [
136 | MigrationGenerator::class,
137 | ModelGenerator::class,
138 | RepositoryGenerator::class,
139 | RequestGenerator::class,
140 | ControllerGenerator::class,
141 | ViewGenerator::class,
142 | RoutesGenerator::class,
143 | MenuGenerator::class,
144 | ];
145 |
146 | mockShouldHaveCalledRollbackGenerator($shouldHaveCalledGenerators);
147 |
148 | $shouldNotHaveCalledGenerator = [
149 | APIRequestGenerator::class,
150 | APIControllerGenerator::class,
151 | APIRoutesGenerator::class,
152 | ];
153 |
154 | mockShouldNotHaveCalledRollbackGenerators($shouldNotHaveCalledGenerator);
155 |
156 | config()->set('laravel_generator.options.tests', true);
157 |
158 | artisan(RollbackGeneratorCommand::class, ['model' => 'User', 'type' => 'scaffold']);
159 | });
160 |
--------------------------------------------------------------------------------
/tests/Commands/ScaffoldGeneratorCommandTest.php:
--------------------------------------------------------------------------------
1 | 'Post'])
57 | ->expectsQuestion('Field: (name db_type html_type options)', 'title body text')
58 | ->expectsQuestion('Enter validations: ', 'required')
59 | ->expectsQuestion('Field: (name db_type html_type options)', 'exit')
60 | ->expectsQuestion(PHP_EOL.'Do you want to migrate database? [y|N]', false)
61 | ->assertSuccessful();
62 | });
63 |
64 | it('generates all files for scaffold from fields file', function () {
65 | $fileUtils = FileUtils::fake([
66 | 'createFile' => true,
67 | 'createDirectoryIfNotExist' => true,
68 | 'deleteFile' => true,
69 | ]);
70 |
71 | $shouldHaveCalledGenerators = [
72 | MigrationGenerator::class,
73 | ModelGenerator::class,
74 | RepositoryGenerator::class,
75 | RequestGenerator::class,
76 | ControllerGenerator::class,
77 | ViewGenerator::class,
78 | RoutesGenerator::class,
79 | MenuGenerator::class,
80 | FactoryGenerator::class,
81 | ];
82 |
83 | mockShouldHaveCalledGenerateMethod($shouldHaveCalledGenerators);
84 |
85 | $shouldNotHaveCalledGenerator = [
86 | RepositoryTestGenerator::class,
87 | APITestGenerator::class,
88 | APIRequestGenerator::class,
89 | APIControllerGenerator::class,
90 | APIRoutesGenerator::class,
91 | SeederGenerator::class,
92 | ];
93 |
94 | mockShouldNotHaveCalledGenerateMethod($shouldNotHaveCalledGenerator);
95 |
96 | config()->set('laravel_generator.options.factory', true);
97 |
98 | $modelSchemaFile = __DIR__.'/../fixtures/model_schema/Post.json';
99 |
100 | $fileUtils->shouldReceive('getFile')
101 | ->withArgs([$modelSchemaFile])
102 | ->andReturn(file_get_contents($modelSchemaFile));
103 | $fileUtils->shouldReceive('getFile')
104 | ->andReturn('');
105 |
106 | artisan(ScaffoldGeneratorCommand::class, ['model' => 'Post', '--fieldsFile' => $modelSchemaFile])
107 | ->expectsQuestion(PHP_EOL.'Do you want to migrate database? [y|N]', false)
108 | ->assertSuccessful();
109 | });
110 |
--------------------------------------------------------------------------------
/tests/Generators/APIControllerGeneratorTest.php:
--------------------------------------------------------------------------------
1 | getViewName();
22 |
23 | expect($viewName)->toBe('repository.controller');
24 | });
25 |
26 | test('uses model controller template', function () {
27 | config()->set('laravel_generator.options.repository_pattern', false);
28 |
29 | fakeGeneratorConfig();
30 |
31 | /** @var APIControllerGenerator $generator */
32 | $generator = app(APIControllerGenerator::class);
33 |
34 | $viewName = $generator->getViewName();
35 |
36 | expect($viewName)->toBe('model.controller');
37 | });
38 |
39 | test('used resource repository controller template', function () {
40 | config()->set('laravel_generator.options.resources', true);
41 |
42 | fakeGeneratorConfig();
43 |
44 | /** @var APIControllerGenerator $generator */
45 | $generator = app(APIControllerGenerator::class);
46 |
47 | $viewName = $generator->getViewName();
48 |
49 | expect($viewName)->toBe('repository.controller_resource');
50 | });
51 |
--------------------------------------------------------------------------------
/tests/Helpers/HelpersTest.php:
--------------------------------------------------------------------------------
1 | toBe($modelNames[$i]);
13 | $i++;
14 | }
15 | });
16 |
--------------------------------------------------------------------------------
/tests/Pest.php:
--------------------------------------------------------------------------------
1 | in(__DIR__);
15 |
16 | /*
17 | |--------------------------------------------------------------------------
18 | | Expectations
19 | |--------------------------------------------------------------------------
20 | |
21 | | When you're writing tests, you often need to check that values meet certain conditions. The
22 | | "expect()" function gives you access to a set of "expectations" methods that you can use
23 | | to assert different things. Of course, you may extend the Expectation API at any time.
24 | |
25 | */
26 |
27 | expect()->extend('toBeOne', function () {
28 | return $this->toBe(1);
29 | });
30 |
31 | /*
32 | |--------------------------------------------------------------------------
33 | | Functions
34 | |--------------------------------------------------------------------------
35 | |
36 | | While Pest is very powerful out-of-the-box, you may have some testing code specific to your
37 | | project that you don't want to repeat in every file. Here you can also expose helpers as
38 | | global functions to help you to reduce the number of lines of code in your test files.
39 | |
40 | */
41 |
42 | include_once 'TestHelpers.php';
43 |
--------------------------------------------------------------------------------
/tests/TestCase.php:
--------------------------------------------------------------------------------
1 | shouldReceive('generate')
15 | ->once()
16 | ->andReturn(true);
17 |
18 | app()->singleton($generator, function () use ($mock) {
19 | return $mock;
20 | });
21 |
22 | $mockedObjects[] = $mock;
23 | }
24 |
25 | return $mockedObjects;
26 | }
27 |
28 | function mockShouldNotHaveCalledGenerateMethod(array $shouldNotHaveCalledGenerator): array
29 | {
30 | $mockedObjects = [];
31 |
32 | foreach ($shouldNotHaveCalledGenerator as $generator) {
33 | $mock = m::mock($generator);
34 |
35 | $mock->shouldNotReceive('generate');
36 |
37 | app()->singleton($generator, function () use ($mock) {
38 | return $mock;
39 | });
40 |
41 | $mockedObjects[] = $mock;
42 | }
43 |
44 | return $mockedObjects;
45 | }
46 |
47 | function fakeGeneratorConfig()
48 | {
49 | $fakeConfig = new GeneratorConfig();
50 | $command = fakeGeneratorCommand();
51 | $fakeConfig->setCommand($command);
52 | $fakeConfig->init();
53 |
54 | app()->singleton(GeneratorConfig::class, function () use ($fakeConfig) {
55 | return $fakeConfig;
56 | });
57 |
58 | return $fakeConfig;
59 | }
60 |
61 | function fakeGeneratorCommand($options = [])
62 | {
63 | $mock = m::mock(Command::class);
64 |
65 | $mock->shouldReceive('argument')->withArgs(['model'])->andReturn('FakeModel');
66 | if (empty($options)) {
67 | $mock->shouldReceive('option')->withAnyArgs()->andReturn('');
68 | } else {
69 | foreach ($options as $option => $value) {
70 | $mock->shouldReceive('option')->withArgs([$option])->andReturn($value);
71 | }
72 | }
73 |
74 | return $mock;
75 | }
76 |
--------------------------------------------------------------------------------
/tests/fixtures/model_schema/Post.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "name": "id",
4 | "dbType": "id",
5 | "htmlType": null,
6 | "validations": null,
7 | "searchable": false,
8 | "fillable": false,
9 | "primary": true,
10 | "inForm": false,
11 | "inIndex": false,
12 | "inView": false
13 | },
14 | {
15 | "name": "user_id",
16 | "dbType": "unsignedBigInteger:foreign,users,id",
17 | "htmlType": "text",
18 | "relation": "mt1,User,user_id,id",
19 | "validations": "required",
20 | "searchable": false,
21 | "fillable": true,
22 | "primary": false,
23 | "inForm": true,
24 | "inIndex": true,
25 | "inView": true
26 | },
27 | {
28 | "name": "title",
29 | "dbType": "string",
30 | "htmlType": "text",
31 | "validations": "required",
32 | "searchable": true,
33 | "fillable": true,
34 | "primary": false,
35 | "inForm": true,
36 | "inIndex": true,
37 | "inView": true
38 | },
39 | {
40 | "name": "body",
41 | "dbType": "text",
42 | "htmlType": "textarea",
43 | "validations": "",
44 | "searchable": true,
45 | "fillable": true,
46 | "primary": false,
47 | "inForm": true,
48 | "inIndex": true,
49 | "inView": true
50 | },
51 | {
52 | "name": "created_at",
53 | "dbType": "timestamp",
54 | "htmlType": null,
55 | "validations": null,
56 | "searchable": false,
57 | "fillable": false,
58 | "primary": false,
59 | "inForm": false,
60 | "inIndex": false,
61 | "inView": true
62 | },
63 | {
64 | "name": "updated_at",
65 | "dbType": "timestamp",
66 | "htmlType": null,
67 | "validations": null,
68 | "searchable": false,
69 | "fillable": false,
70 | "primary": false,
71 | "inForm": false,
72 | "inIndex": false,
73 | "inView": true
74 | }
75 | ]
76 |
--------------------------------------------------------------------------------
/views/api/docs/controller/controller.blade.php:
--------------------------------------------------------------------------------
1 | /**
2 | * Class {{ $config->modelNames->name }}APIController
3 | */
--------------------------------------------------------------------------------
/views/api/docs/controller/destroy.blade.php:
--------------------------------------------------------------------------------
1 | /**
2 | * Remove the specified {{ $config->modelNames->name }} from storage.
3 | * DELETE /{{ $config->modelNames->dashedPlural }}/{id}
4 | *
5 | * @throws \Exception
6 | */
--------------------------------------------------------------------------------
/views/api/docs/controller/index.blade.php:
--------------------------------------------------------------------------------
1 | /**
2 | * Display a listing of the {{ $config->modelNames->plural }}.
3 | * GET|HEAD /{{ $config->modelNames->dashedPlural }}
4 | */
--------------------------------------------------------------------------------
/views/api/docs/controller/show.blade.php:
--------------------------------------------------------------------------------
1 | /**
2 | * Display the specified {{ $config->modelNames->name }}.
3 | * GET|HEAD /{{ $config->modelNames->dashedPlural }}/{id}
4 | */
--------------------------------------------------------------------------------
/views/api/docs/controller/store.blade.php:
--------------------------------------------------------------------------------
1 | /**
2 | * Store a newly created {{ $config->modelNames->name }} in storage.
3 | * POST /{{ $config->modelNames->dashedPlural }}
4 | */
--------------------------------------------------------------------------------
/views/api/docs/controller/update.blade.php:
--------------------------------------------------------------------------------
1 | /**
2 | * Update the specified {{ $config->modelNames->name }} in storage.
3 | * PUT/PATCH /{{ $config->modelNames->dashedPlural }}/{id}
4 | */
--------------------------------------------------------------------------------
/views/api/request/create.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "namespaces->apiRequest }};
6 |
7 | use {{ $config->namespaces->model }}\{{ $config->modelNames->name }};
8 | use InfyOm\Generator\Request\APIRequest;
9 |
10 | class Create{{ $config->modelNames->name }}APIRequest extends APIRequest
11 | {
12 | /**
13 | * Determine if the user is authorized to make this request.
14 | *
15 | * @return bool
16 | */
17 | public function authorize()
18 | {
19 | return true;
20 | }
21 |
22 | /**
23 | * Get the validation rules that apply to the request.
24 | *
25 | * @return array
26 | */
27 | public function rules()
28 | {
29 | return {{ $config->modelNames->name }}::$rules;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/views/api/request/update.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "namespaces->apiRequest }};
6 |
7 | use {{ $config->namespaces->model }}\{{ $config->modelNames->name }};
8 | use InfyOm\Generator\Request\APIRequest;
9 |
10 | class Update{{ $config->modelNames->name }}APIRequest extends APIRequest
11 | {
12 | /**
13 | * Determine if the user is authorized to make this request.
14 | *
15 | * @return bool
16 | */
17 | public function authorize()
18 | {
19 | return true;
20 | }
21 |
22 | /**
23 | * Get the validation rules that apply to the request.
24 | *
25 | * @return array
26 | */
27 | public function rules()
28 | {
29 | $rules = {{ $config->modelNames->name }}::$rules;
30 | {!! $uniqueRules !!}
31 | return $rules;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/views/api/resource/resource.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "namespaces->apiResource }};
6 |
7 | use Illuminate\Http\Resources\Json\JsonResource;
8 |
9 | class {{ $config->modelNames->name }}Resource extends JsonResource
10 | {
11 | /**
12 | * Transform the resource into an array.
13 | *
14 | * @param \Illuminate\Http\Request $request
15 | * @return array
16 | */
17 | public function toArray($request)
18 | {
19 | return [
20 | {!! $fields !!}
21 | ];
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/views/api/routes.blade.php:
--------------------------------------------------------------------------------
1 | Route::resource('{{ $config->prefixes->getRoutePrefixWith('/') }}{{ $config->modelNames->dashedPlural }}', {{ $config->namespaces->apiController }}\{{ $config->modelNames->name }}APIController::class){!! infy_nl_tab() !!}->except(['create', 'edit'])@if(!$config->prefixes->route);@endif
2 | @if($config->prefixes->route){!! infy_nl_tab().'->names(['.infy_nl_tab(1,2).implode(','.infy_nl_tab(1, 2), create_resource_route_names($config->prefixes->getRoutePrefixWith('.').$config->modelNames->camelPlural)).infy_nl_tab().']);' !!}@endif
--------------------------------------------------------------------------------
/views/api/test/api_test.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "namespaces->apiTests }};
6 |
7 | use Illuminate\Foundation\Testing\WithoutMiddleware;
8 | use Illuminate\Foundation\Testing\DatabaseTransactions;
9 | use {{ $config->namespaces->tests }}\TestCase;
10 | use {{ $config->namespaces->tests }}\ApiTestTrait;
11 | use {{ $config->namespaces->model }}\{{ $config->modelNames->name }};
12 |
13 | class {{ $config->modelNames->name }}ApiTest extends TestCase
14 | {
15 | use ApiTestTrait, WithoutMiddleware, DatabaseTransactions;
16 |
17 | /**
18 | * @test
19 | */
20 | public function test_create_{{ $config->modelNames->snake }}()
21 | {
22 | ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::factory()->make()->toArray();
23 |
24 | $this->response = $this->json(
25 | 'POST',
26 | '/{{ $config->apiPrefix }}/{{ $config->modelNames->dashedPlural }}', ${{ $config->modelNames->camel }}
27 | );
28 |
29 | $this->assertApiResponse(${{ $config->modelNames->camel }});
30 | }
31 |
32 | /**
33 | * @test
34 | */
35 | public function test_read_{{ $config->modelNames->snake }}()
36 | {
37 | ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::factory()->create();
38 |
39 | $this->response = $this->json(
40 | 'GET',
41 | '/{{ $config->apiPrefix }}/{{ $config->modelNames->dashedPlural }}/'.${{ $config->modelNames->camel }}->{{ $config->primaryName }}
42 | );
43 |
44 | $this->assertApiResponse(${{ $config->modelNames->camel }}->toArray());
45 | }
46 |
47 | /**
48 | * @test
49 | */
50 | public function test_update_{{ $config->modelNames->snake }}()
51 | {
52 | ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::factory()->create();
53 | $edited{{ $config->modelNames->name }} = {{ $config->modelNames->name }}::factory()->make()->toArray();
54 |
55 | $this->response = $this->json(
56 | 'PUT',
57 | '/{{ $config->apiPrefix }}/{{ $config->modelNames->dashedPlural }}/'.${{ $config->modelNames->camel }}->{{ $config->primaryName }},
58 | $edited{{ $config->modelNames->name }}
59 | );
60 |
61 | $this->assertApiResponse($edited{{ $config->modelNames->name }});
62 | }
63 |
64 | /**
65 | * @test
66 | */
67 | public function test_delete_{{ $config->modelNames->snake }}()
68 | {
69 | ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::factory()->create();
70 |
71 | $this->response = $this->json(
72 | 'DELETE',
73 | '/{{ $config->apiPrefix }}/{{ $config->modelNames->dashedPlural }}/'.${{ $config->modelNames->camel }}->{{ $config->primaryName }}
74 | );
75 |
76 | $this->assertApiSuccess();
77 | $this->response = $this->json(
78 | 'GET',
79 | '/{{ $config->apiPrefix }}/{{ $config->modelNames->dashedPlural }}/'.${{ $config->modelNames->camel }}->{{ $config->primaryName }}
80 | );
81 |
82 | $this->response->assertStatus(404);
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/views/api/test/api_test_trait.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "assertApiSuccess();
13 |
14 | $response = json_decode($this->response->getContent(), true);
15 | $responseData = $response['data'];
16 |
17 | $this->assertNotEmpty($responseData['id']);
18 | $this->assertModelData($actualData, $responseData);
19 | }
20 |
21 | public function assertApiSuccess()
22 | {
23 | $this->response->assertStatus(200);
24 | $this->response->assertJson(['success' => true]);
25 | }
26 |
27 | public function assertModelData(Array $actualData, Array $expectedData)
28 | {
29 | foreach ($actualData as $key => $value) {
30 | if (in_array($key, {!! $timestamps !!})) {
31 | continue;
32 | }
33 | $this->assertEquals($actualData[$key], $expectedData[$key]);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/views/migration.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "tableName }}', function (Blueprint $table) {
19 | {!! $fields !!}
20 | });
21 | }
22 |
23 | /**
24 | * Reverse the migrations.
25 | *
26 | * @return void
27 | */
28 | public function down()
29 | {
30 | Schema::drop('{{ $config->tableName }}');
31 | }
32 | };
33 |
--------------------------------------------------------------------------------
/views/model/factory.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "namespaces->factory }};
6 |
7 | use {{ $config->namespaces->model }}\{{ $config->modelNames->name }};
8 | use Illuminate\Database\Eloquent\Factories\Factory;
9 | {!! $usedRelations !!}
10 |
11 | class {{ $config->modelNames->name }}Factory extends Factory
12 | {
13 | /**
14 | * The name of the factory's corresponding model.
15 | *
16 | * @var string
17 | */
18 | protected $model = {{ $config->modelNames->name }}::class;
19 |
20 | /**
21 | * Define the model's default state.
22 | *
23 | * @return array
24 | */
25 | public function definition()
26 | {
27 | {!! $relations !!}
28 | return [
29 | {!! $fields !!}
30 | ];
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/views/model/model.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "namespaces->model }};
6 |
7 | use Illuminate\Database\Eloquent\Model;
8 | @if($config->options->softDelete) {{ 'use Illuminate\Database\Eloquent\SoftDeletes;' }}@endif
9 | @if($config->options->tests or $config->options->factory) {{ 'use Illuminate\Database\Eloquent\Factories\HasFactory;' }}@endif
10 |
11 | @if(isset($swaggerDocs)){!! $swaggerDocs !!}@endif
12 | class {{ $config->modelNames->name }} extends Model
13 | {
14 | @if($config->options->softDelete) {{ infy_tab().'use SoftDeletes;' }}@endif
15 | @if($config->options->tests or $config->options->factory){{ infy_tab().'use HasFactory;' }}@endif
16 | public $table = '{{ $config->tableName }}';
17 |
18 | @if($customPrimaryKey)@tab()protected $primaryKey = '{{ $customPrimaryKey }}';@nls(2)@endif
19 | @if($config->connection)@tab()protected $connection = '{{ $config->connection }}';@nls(2)@endif
20 | @if(!$timestamps)@tab()public $timestamps = false;@nls(2)@endif
21 | @if($customSoftDelete)@tab()protected $dates = ['{{ $customSoftDelete }}'];@nls(2)@endif
22 | @if($customCreatedAt)@tab()const CREATED_AT = '{{ $customCreatedAt }}';@nls(2)@endif
23 | @if($customUpdatedAt)@tab()const UPDATED_AT = '{{ $customUpdatedAt }}';@nls(2)@endif
24 | public $fillable = [
25 | {!! $fillables !!}
26 | ];
27 |
28 | protected $casts = [
29 | {!! $casts !!}
30 | ];
31 |
32 | public static array $rules = [
33 | {!! $rules !!}
34 | ];
35 |
36 | {!! $relations !!}
37 | }
38 |
--------------------------------------------------------------------------------
/views/model/relationship.blade.php:
--------------------------------------------------------------------------------
1 | public function {{ $functionName }}(): \Illuminate\Database\Eloquent\Relations\{{ $relationClass }}
2 | {
3 | return $this->{{ $relation }}(\{{ $config->namespaces->model }}\{{ $relatedModel }}::class{!! $fields !!});
4 | }
--------------------------------------------------------------------------------
/views/model/seeder.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "namespaces->seeder }};
6 |
7 | use Illuminate\Database\Seeder;
8 |
9 | class {{ $config->modelNames->plural }}TableSeeder extends Seeder
10 | {
11 | /**
12 | * Run the database seeds.
13 | *
14 | * @return void
15 | */
16 | public function run()
17 | {
18 |
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/views/repository/repository.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "namespaces->repository }};
6 |
7 | use {{ $config->namespaces->model }}\{{ $config->modelNames->name }};
8 | use {{ $config->namespaces->app }}\Repositories\BaseRepository;
9 |
10 | class {{ $config->modelNames->name }}Repository extends BaseRepository
11 | {
12 | protected $fieldSearchable = [
13 | {!! $fieldSearchable !!}
14 | ];
15 |
16 | public function getFieldsSearchable(): array
17 | {
18 | return $this->fieldSearchable;
19 | }
20 |
21 | public function model(): string
22 | {
23 | return {{ $config->modelNames->name }}::class;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/views/repository/repository_test.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "namespaces->repositoryTests }};
6 |
7 | use {{ $config->namespaces->model }}\{{ $config->modelNames->name }};
8 | use {{ $config->namespaces->repository }}\{{ $config->modelNames->name }}Repository;
9 | use Illuminate\Foundation\Testing\DatabaseTransactions;
10 | use {{ $config->namespaces->tests }}\TestCase;
11 | use {{ $config->namespaces->tests }}\ApiTestTrait;
12 |
13 | class {{ $config->modelNames->name }}RepositoryTest extends TestCase
14 | {
15 | use ApiTestTrait, DatabaseTransactions;
16 |
17 | protected {{ $config->modelNames->name }}Repository ${{ $config->modelNames->camel }}Repo;
18 |
19 | public function setUp() : void
20 | {
21 | parent::setUp();
22 | $this->{{ $config->modelNames->camel }}Repo = app({{ $config->modelNames->name }}Repository::class);
23 | }
24 |
25 | /**
26 | * @test create
27 | */
28 | public function test_create_{{ $config->modelNames->snake }}()
29 | {
30 | ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::factory()->make()->toArray();
31 |
32 | $created{{ $config->modelNames->name }} = $this->{{ $config->modelNames->camel }}Repo->create(${{ $config->modelNames->camel }});
33 |
34 | $created{{ $config->modelNames->name }} = $created{{ $config->modelNames->name }}->toArray();
35 | $this->assertArrayHasKey('id', $created{{ $config->modelNames->name }});
36 | $this->assertNotNull($created{{ $config->modelNames->name }}['id'], 'Created {{ $config->modelNames->name }} must have id specified');
37 | $this->assertNotNull({{ $config->modelNames->name }}::find($created{{ $config->modelNames->name }}['id']), '{{ $config->modelNames->name }} with given id must be in DB');
38 | $this->assertModelData(${{ $config->modelNames->camel }}, $created{{ $config->modelNames->name }});
39 | }
40 |
41 | /**
42 | * @test read
43 | */
44 | public function test_read_{{ $config->modelNames->snake }}()
45 | {
46 | ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::factory()->create();
47 |
48 | $db{{ $config->modelNames->name }} = $this->{{ $config->modelNames->camel }}Repo->find(${{ $config->modelNames->camel }}->{{ $config->primaryName }});
49 |
50 | $db{{ $config->modelNames->name }} = $db{{ $config->modelNames->name }}->toArray();
51 | $this->assertModelData(${{ $config->modelNames->camel }}->toArray(), $db{{ $config->modelNames->name }});
52 | }
53 |
54 | /**
55 | * @test update
56 | */
57 | public function test_update_{{ $config->modelNames->snake }}()
58 | {
59 | ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::factory()->create();
60 | $fake{{ $config->modelNames->name }} = {{ $config->modelNames->name }}::factory()->make()->toArray();
61 |
62 | $updated{{ $config->modelNames->name }} = $this->{{ $config->modelNames->camel }}Repo->update($fake{{ $config->modelNames->name }}, ${{ $config->modelNames->camel }}->{{ $config->primaryName }});
63 |
64 | $this->assertModelData($fake{{ $config->modelNames->name }}, $updated{{ $config->modelNames->name }}->toArray());
65 | $db{{ $config->modelNames->name }} = $this->{{ $config->modelNames->camel }}Repo->find(${{ $config->modelNames->camel }}->{{ $config->primaryName }});
66 | $this->assertModelData($fake{{ $config->modelNames->name }}, $db{{ $config->modelNames->name }}->toArray());
67 | }
68 |
69 | /**
70 | * @test delete
71 | */
72 | public function test_delete_{{ $config->modelNames->snake }}()
73 | {
74 | ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::factory()->create();
75 |
76 | $resp = $this->{{ $config->modelNames->camel }}Repo->delete(${{ $config->modelNames->camel }}->{{ $config->primaryName }});
77 |
78 | $this->assertTrue($resp);
79 | $this->assertNull({{ $config->modelNames->name }}::find(${{ $config->modelNames->camel }}->{{ $config->primaryName }}), '{{ $config->modelNames->name }} should not exist in DB');
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/views/scaffold/controller/controller.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "namespaces->controller }};
6 |
7 | @if(config('laravel_generator.tables') == 'datatables')
8 | use {{ $config->namespaces->dataTables }}\{{ $config->modelNames->name }}DataTable;
9 | @endif
10 | use {{ $config->namespaces->request }}\Create{{ $config->modelNames->name }}Request;
11 | use {{ $config->namespaces->request }}\Update{{ $config->modelNames->name }}Request;
12 | use {{ $config->namespaces->app }}\Http\Controllers\AppBaseController;
13 | use {{ $config->namespaces->model }}\{{ $config->modelNames->name }};
14 | use Illuminate\Http\Request;
15 | use Flash;
16 |
17 | class {{ $config->modelNames->name }}Controller extends AppBaseController
18 | {
19 | /**
20 | * Display a listing of the {{ $config->modelNames->name }}.
21 | */
22 | {!! $indexMethod !!}
23 |
24 | /**
25 | * Show the form for creating a new {{ $config->modelNames->name }}.
26 | */
27 | public function create()
28 | {
29 | return view('{{ $config->prefixes->getViewPrefixForInclude() }}{{ $config->modelNames->snakePlural }}.create');
30 | }
31 |
32 | /**
33 | * Store a newly created {{ $config->modelNames->name }} in storage.
34 | */
35 | public function store(Create{{ $config->modelNames->name }}Request $request)
36 | {
37 | $input = $request->all();
38 |
39 | /** @var {{ $config->modelNames->name }} ${{ $config->modelNames->camel }} */
40 | ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::create($input);
41 |
42 | @include('laravel-generator::scaffold.controller.messages.save_success')
43 |
44 | return redirect(route('{{ $config->prefixes->getRoutePrefixWith('.') }}{{ $config->modelNames->camelPlural }}.index'));
45 | }
46 |
47 | /**
48 | * Display the specified {{ $config->modelNames->name }}.
49 | */
50 | public function show($id)
51 | {
52 | /** @var {{ $config->modelNames->name }} ${{ $config->modelNames->camel }} */
53 | ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::find($id);
54 |
55 | @include('laravel-generator::scaffold.controller.messages.not_found')
56 |
57 | return view('{{ $config->prefixes->getViewPrefixForInclude() }}{{ $config->modelNames->snakePlural }}.show')->with('{{ $config->modelNames->camel }}', ${{ $config->modelNames->camel }});
58 | }
59 |
60 | /**
61 | * Show the form for editing the specified {{ $config->modelNames->name }}.
62 | */
63 | public function edit($id)
64 | {
65 | /** @var {{ $config->modelNames->name }} ${{ $config->modelNames->camel }} */
66 | ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::find($id);
67 |
68 | @include('laravel-generator::scaffold.controller.messages.not_found')
69 |
70 | return view('{{ $config->prefixes->getViewPrefixForInclude() }}{{ $config->modelNames->snakePlural }}.edit')->with('{{ $config->modelNames->camel }}', ${{ $config->modelNames->camel }});
71 | }
72 |
73 | /**
74 | * Update the specified {{ $config->modelNames->name }} in storage.
75 | */
76 | public function update($id, Update{{ $config->modelNames->name }}Request $request)
77 | {
78 | /** @var {{ $config->modelNames->name }} ${{ $config->modelNames->camel }} */
79 | ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::find($id);
80 |
81 | @include('laravel-generator::scaffold.controller.messages.not_found')
82 |
83 | ${{ $config->modelNames->camel }}->fill($request->all());
84 | ${{ $config->modelNames->camel }}->save();
85 |
86 | @include('laravel-generator::scaffold.controller.messages.update_success')
87 |
88 | return redirect(route('{{ $config->prefixes->getRoutePrefixWith('.') }}{{ $config->modelNames->camelPlural }}.index'));
89 | }
90 |
91 | /**
92 | * Remove the specified {{ $config->modelNames->name }} from storage.
93 | *
94 | * @throws \Exception
95 | */
96 | public function destroy($id)
97 | {
98 | /** @var {{ $config->modelNames->name }} ${{ $config->modelNames->camel }} */
99 | ${{ $config->modelNames->camel }} = {{ $config->modelNames->name }}::find($id);
100 |
101 | @include('laravel-generator::scaffold.controller.messages.not_found')
102 |
103 | ${{ $config->modelNames->camel }}->delete();
104 |
105 | @include('laravel-generator::scaffold.controller.messages.delete_success')
106 |
107 | return redirect(route('{{ $config->prefixes->getRoutePrefixWith('.') }}{{ $config->modelNames->camelPlural }}.index'));
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/views/scaffold/controller/controller_repository.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "namespaces->controller }};
6 |
7 | @if(config('laravel_generator.tables') === 'datatables')
8 | use {{ $config->namespaces->dataTables }}\{{ $config->modelNames->name }}DataTable;
9 | @endif
10 | use {{ $config->namespaces->request }}\Create{{ $config->modelNames->name }}Request;
11 | use {{ $config->namespaces->request }}\Update{{ $config->modelNames->name }}Request;
12 | use {{ $config->namespaces->app }}\Http\Controllers\AppBaseController;
13 | use {{ $config->namespaces->repository }}\{{ $config->modelNames->name }}Repository;
14 | use Illuminate\Http\Request;
15 | use Flash;
16 |
17 | class {{ $config->modelNames->name }}Controller extends AppBaseController
18 | {
19 | /** @var {{ $config->modelNames->name }}Repository ${{ $config->modelNames->camel }}Repository*/
20 | private ${{ $config->modelNames->camel }}Repository;
21 |
22 | public function __construct({{ $config->modelNames->name }}Repository ${{ $config->modelNames->camel }}Repo)
23 | {
24 | $this->{{ $config->modelNames->camel }}Repository = ${{ $config->modelNames->camel }}Repo;
25 | }
26 |
27 | /**
28 | * Display a listing of the {{ $config->modelNames->name }}.
29 | */
30 | {!! $indexMethod !!}
31 |
32 | /**
33 | * Show the form for creating a new {{ $config->modelNames->name }}.
34 | */
35 | public function create()
36 | {
37 | return view('{{ $config->prefixes->getViewPrefixForInclude() }}{{ $config->modelNames->snakePlural }}.create');
38 | }
39 |
40 | /**
41 | * Store a newly created {{ $config->modelNames->name }} in storage.
42 | */
43 | public function store(Create{{ $config->modelNames->name }}Request $request)
44 | {
45 | $input = $request->all();
46 |
47 | ${{ $config->modelNames->camel }} = $this->{{ $config->modelNames->camel }}Repository->create($input);
48 |
49 | @include('laravel-generator::scaffold.controller.messages.save_success')
50 |
51 | return redirect(route('{{ $config->prefixes->getRoutePrefixWith('.') }}{{ $config->modelNames->camelPlural }}.index'));
52 | }
53 |
54 | /**
55 | * Display the specified {{ $config->modelNames->name }}.
56 | */
57 | public function show($id)
58 | {
59 | ${{ $config->modelNames->camel }} = $this->{{ $config->modelNames->camel }}Repository->find($id);
60 |
61 | @include('laravel-generator::scaffold.controller.messages.not_found')
62 |
63 | return view('{{ $config->prefixes->getViewPrefixForInclude() }}{{ $config->modelNames->snakePlural }}.show')->with('{{ $config->modelNames->camel }}', ${{ $config->modelNames->camel }});
64 | }
65 |
66 | /**
67 | * Show the form for editing the specified {{ $config->modelNames->name }}.
68 | */
69 | public function edit($id)
70 | {
71 | ${{ $config->modelNames->camel }} = $this->{{ $config->modelNames->camel }}Repository->find($id);
72 |
73 | @include('laravel-generator::scaffold.controller.messages.not_found')
74 |
75 | return view('{{ $config->prefixes->getViewPrefixForInclude() }}{{ $config->modelNames->snakePlural }}.edit')->with('{{ $config->modelNames->camel }}', ${{ $config->modelNames->camel }});
76 | }
77 |
78 | /**
79 | * Update the specified {{ $config->modelNames->name }} in storage.
80 | */
81 | public function update($id, Update{{ $config->modelNames->name }}Request $request)
82 | {
83 | ${{ $config->modelNames->camel }} = $this->{{ $config->modelNames->camel }}Repository->find($id);
84 |
85 | @include('laravel-generator::scaffold.controller.messages.not_found')
86 |
87 | ${{ $config->modelNames->camel }} = $this->{{ $config->modelNames->camel }}Repository->update($request->all(), $id);
88 |
89 | @include('laravel-generator::scaffold.controller.messages.update_success')
90 |
91 | return redirect(route('{{ $config->prefixes->getRoutePrefixWith('.') }}{{ $config->modelNames->camelPlural }}.index'));
92 | }
93 |
94 | /**
95 | * Remove the specified {{ $config->modelNames->name }} from storage.
96 | *
97 | * @throws \Exception
98 | */
99 | public function destroy($id)
100 | {
101 | ${{ $config->modelNames->camel }} = $this->{{ $config->modelNames->camel }}Repository->find($id);
102 |
103 | @include('laravel-generator::scaffold.controller.messages.not_found')
104 |
105 | $this->{{ $config->modelNames->camel }}Repository->delete($id);
106 |
107 | @include('laravel-generator::scaffold.controller.messages.delete_success')
108 |
109 | return redirect(route('{{ $config->prefixes->getRoutePrefixWith('.') }}{{ $config->modelNames->camelPlural }}.index'));
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/views/scaffold/controller/index_method.blade.php:
--------------------------------------------------------------------------------
1 | public function index(Request $request)
2 | {
3 | /** @var {{ $config->modelNames->name }} ${{ $config->modelNames->camelPlural }} */
4 | ${{ $config->modelNames->camelPlural }} = {{ $config->modelNames->name }}::{!! $renderType !!};
5 |
6 | return view('{{ $config->prefixes->getViewPrefixForInclude() }}{{ $config->modelNames->snakePlural }}.index')
7 | ->with('{{ $config->modelNames->camelPlural }}', ${{ $config->modelNames->camelPlural }});
8 | }
9 |
--------------------------------------------------------------------------------
/views/scaffold/controller/index_method_datatable.blade.php:
--------------------------------------------------------------------------------
1 | public function index({{ $config->modelNames->name }}DataTable ${{ $config->modelNames->camel }}DataTable)
2 | {
3 | return ${{ $config->modelNames->camel }}DataTable->render('{{ $config->modelNames->snakePlural }}.index');
4 | }
5 |
--------------------------------------------------------------------------------
/views/scaffold/controller/index_method_livewire.blade.php:
--------------------------------------------------------------------------------
1 | public function index(Request $request)
2 | {
3 | return view('{{ $config->modelNames->snakePlural }}.index');
4 | }
--------------------------------------------------------------------------------
/views/scaffold/controller/index_method_repository.blade.php:
--------------------------------------------------------------------------------
1 | public function index(Request $request)
2 | {
3 | ${{ $config->modelNames->camelPlural }} = $this->{{ $config->modelNames->camel }}Repository->{!! $renderType !!};
4 |
5 | return view('{{ $config->prefixes->getViewPrefixForInclude() }}{{ $config->modelNames->snakePlural }}.index')
6 | ->with('{{ $config->modelNames->camelPlural }}', ${{ $config->modelNames->camelPlural }});
7 | }
--------------------------------------------------------------------------------
/views/scaffold/controller/messages/delete_success.blade.php:
--------------------------------------------------------------------------------
1 | @if($config->options->localized)
2 | Flash::success(__('messages.deleted', ['model' => __('models/{{ $config->modelNames->camelPlural }}.singular')]));
3 | @else
4 | Flash::success('{{ $config->modelNames->human }} deleted successfully.');
5 | @endif
--------------------------------------------------------------------------------
/views/scaffold/controller/messages/not_found.blade.php:
--------------------------------------------------------------------------------
1 | if (empty(${{ $config->modelNames->camel }})) {
2 | @if($config->options->localized)
3 | Flash::error(__('models/{{ $config->modelNames->camelPlural }}.singular').' '.__('messages.not_found'));
4 | @else
5 | Flash::error('{{ $config->modelNames->human }} not found');
6 | @endif
7 |
8 | return redirect(route('{{ $config->prefixes->getRoutePrefixWith('.') }}{{ $config->modelNames->camelPlural }}.index'));
9 | }
10 |
--------------------------------------------------------------------------------
/views/scaffold/controller/messages/save_success.blade.php:
--------------------------------------------------------------------------------
1 | @if($config->options->localized)
2 | Flash::success(__('messages.saved', ['model' => __('models/{{ $config->modelNames->camelPlural }}.singular')]));
3 | @else
4 | Flash::success('{{ $config->modelNames->human }} saved successfully.');
5 | @endif
6 |
--------------------------------------------------------------------------------
/views/scaffold/controller/messages/update_success.blade.php:
--------------------------------------------------------------------------------
1 | @if($config->options->localized)
2 | Flash::success(__('messages.updated', ['model' => __('models/{{ $config->modelNames->camelPlural }}.singular')]));
3 | @else
4 | Flash::success('{{ $config->modelNames->human }} updated successfully.');
5 | @endif
--------------------------------------------------------------------------------
/views/scaffold/controller/model_not_found.blade.php:
--------------------------------------------------------------------------------
1 | if (empty(${{ $config->modelNames->camel }})) {
2 | @if($config->options->localized)
3 | Flash::error(__('models/{{ $config->modelNames->camelPlural }}.singular').' '.__('messages.not_found'));
4 | @else
5 | Flash::error('{{ $config->modelNames->human }} not found');
6 | @endif
7 |
8 | return redirect(route('{{ $config->prefixes->getRoutePrefixWith('.') }}{{ $config->modelNames->camelPlural }}.index'));
9 | }
10 |
--------------------------------------------------------------------------------
/views/scaffold/layouts/datatables_css.blade.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/views/scaffold/layouts/datatables_js.blade.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/views/scaffold/request/create.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "namespaces->request }};
6 |
7 | use {{ $config->namespaces->model }}\{{ $config->modelNames->name }};
8 | use Illuminate\Foundation\Http\FormRequest;
9 |
10 | class Create{{ $config->modelNames->name }}Request extends FormRequest
11 | {
12 | /**
13 | * Determine if the user is authorized to make this request.
14 | *
15 | * @return bool
16 | */
17 | public function authorize()
18 | {
19 | return true;
20 | }
21 |
22 | /**
23 | * Get the validation rules that apply to the request.
24 | *
25 | * @return array
26 | */
27 | public function rules()
28 | {
29 | return {{ $config->modelNames->name }}::$rules;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/views/scaffold/request/update.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "namespaces->request }};
6 |
7 | use {{ $config->namespaces->model }}\{{ $config->modelNames->name }};
8 | use Illuminate\Foundation\Http\FormRequest;
9 |
10 | class Update{{ $config->modelNames->name }}Request extends FormRequest
11 | {
12 | /**
13 | * Determine if the user is authorized to make this request.
14 | *
15 | * @return bool
16 | */
17 | public function authorize()
18 | {
19 | return true;
20 | }
21 |
22 | /**
23 | * Get the validation rules that apply to the request.
24 | *
25 | * @return array
26 | */
27 | public function rules()
28 | {
29 | $rules = {{ $config->modelNames->name }}::$rules;
30 | {!! $uniqueRules !!}
31 | return $rules;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/views/scaffold/routes.blade.php:
--------------------------------------------------------------------------------
1 | Route::resource('{{ $config->prefixes->getRoutePrefixWith('/') }}{{ $config->modelNames->dashedPlural }}', {{ $config->namespaces->controller }}\{{ $config->modelNames->name }}Controller::class)@if(!$config->prefixes->route);@endif
2 | @if($config->prefixes->route){!! infy_nl_tab().'->names(['.infy_nl_tab(1, 2).implode(','.infy_nl_tab(1, 2), create_resource_route_names($config->prefixes->getRoutePrefixWith('.').$config->modelNames->dashedPlural, true)).infy_nl_tab().']);' !!}@endif
--------------------------------------------------------------------------------
/views/scaffold/table/datatable.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "namespaces->dataTables }};
6 |
7 | use {{ $config->namespaces->model }}\{{ $config->modelNames->name }};
8 | @if($config->options->localized)
9 | use Yajra\DataTables\Html\Column;
10 | @endif
11 | use Yajra\DataTables\Services\DataTable;
12 | use Yajra\DataTables\EloquentDataTable;
13 |
14 | class {{ $config->modelNames->name }}DataTable extends DataTable
15 | {
16 | /**
17 | * Build DataTable class.
18 | *
19 | * @param mixed $query Results from query() method.
20 | * @return \Yajra\DataTables\DataTableAbstract
21 | */
22 | public function dataTable($query)
23 | {
24 | $dataTable = new EloquentDataTable($query);
25 |
26 | return $dataTable->addColumn('action', '{{ $config->modelNames->snakePlural }}.datatables_actions');
27 | }
28 |
29 | /**
30 | * Get query source of dataTable.
31 | *
32 | * @param \App\Models\{{ $config->modelNames->name }} $model
33 | * @return \Illuminate\Database\Eloquent\Builder
34 | */
35 | public function query({{ $config->modelNames->name }} $model)
36 | {
37 | return $model->newQuery();
38 | }
39 |
40 | /**
41 | * Optional method if you want to use html builder.
42 | *
43 | * @return \Yajra\DataTables\Html\Builder
44 | */
45 | public function html()
46 | {
47 | return $this->builder()
48 | ->columns($this->getColumns())
49 | ->minifiedAjax()
50 | ->addAction(['width' => '120px', 'printable' => false])
51 | ->parameters([
52 | 'dom' => 'Bfrtip',
53 | 'stateSave' => true,
54 | 'order' => [[0, 'desc']],
55 | 'buttons' => [
56 | // Enable Buttons as per your need
57 | // ['extend' => 'create', 'className' => 'btn btn-default btn-sm no-corner',],
58 | // ['extend' => 'export', 'className' => 'btn btn-default btn-sm no-corner',],
59 | // ['extend' => 'print', 'className' => 'btn btn-default btn-sm no-corner',],
60 | // ['extend' => 'reset', 'className' => 'btn btn-default btn-sm no-corner',],
61 | // ['extend' => 'reload', 'className' => 'btn btn-default btn-sm no-corner',],
62 | ],
63 | @if($config->options->localized)
64 | 'language' => [
65 | 'url' => url('//cdn.datatables.net/plug-ins/1.10.12/i18n/English.json'),
66 | ],
67 | @endif
68 | ]);
69 | }
70 |
71 | /**
72 | * Get columns.
73 | *
74 | * @return array
75 | */
76 | protected function getColumns()
77 | {
78 | return [
79 | {!! $columns !!}
80 | ];
81 | }
82 |
83 | /**
84 | * Get filename for export.
85 | *
86 | * @return string
87 | */
88 | protected function filename(): string
89 | {
90 | return '{{ $config->modelNames->snakePlural }}_datatable_' . time();
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/views/scaffold/table/livewire.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "namespaces->livewireTables }};
6 |
7 | use Laracasts\Flash\Flash;
8 | use Rappasoft\LaravelLivewireTables\DataTableComponent;
9 | use Rappasoft\LaravelLivewireTables\Views\Column;
10 | use {{ $config->namespaces->model }}\{{ $config->modelNames->name }};
11 |
12 | class {{ $config->modelNames->plural }}Table extends DataTableComponent
13 | {
14 | protected $model = {{ $config->modelNames->name }}::class;
15 |
16 | protected $listeners = ['deleteRecord' => 'deleteRecord'];
17 |
18 | public function deleteRecord($id)
19 | {
20 | {{ $config->modelNames->name }}::find($id)->delete();
21 | @if($config->options->localized)
22 | Flash::success(__('messages.deleted', ['model' => __('models/{{ $config->modelNames->camelPlural }}.singular')]));
23 | @else
24 | Flash::success('{{ $config->modelNames->human }} deleted successfully.');
25 | @endif
26 | $this->emit('refreshDatatable');
27 | }
28 |
29 | public function configure(): void
30 | {
31 | $this->setPrimaryKey('{{ $config->primaryName }}');
32 | }
33 |
34 | public function columns(): array
35 | {
36 | return [
37 | {!! $columns !!},
38 | Column::make("Actions", '{{ $config->primaryName }}')
39 | ->format(
40 | fn($value, $row, Column $column) => view('common.livewire-tables.actions', [
41 | 'showUrl' => route('{{ $config->modelNames->dashedPlural }}.show', $row->{{ $config->primaryName }}),
42 | 'editUrl' => route('{{ $config->modelNames->dashedPlural }}.edit', $row->{{ $config->primaryName }}),
43 | 'recordId' => $row->{{ $config->primaryName }},
44 | ])
45 | )
46 | ];
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/views/scaffold/user/create_user_request.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo " 'required',
31 | 'email' => 'required|email|unique:users,email',
32 | 'password' => 'required|confirmed'
33 | ];
34 |
35 | return $rules;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/views/scaffold/user/update_user_request.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "route('user');
30 | $rules = [
31 | 'name' => 'required',
32 | 'email' => 'required|email|unique:users,email,'.$id,
33 | 'password' => 'confirmed'
34 | ];
35 |
36 | return $rules;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/views/scaffold/user/user_controller.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "userRepository = $userRepo;
23 | }
24 |
25 | /**
26 | * Display a listing of the User.
27 | *
28 | * @param Request $request
29 | */
30 | public function index(Request $request)
31 | {
32 | $users = $this->userRepository->paginate(10);
33 |
34 | return view('users.index')->with('users', $users);
35 | }
36 |
37 | /**
38 | * Show the form for creating a new User.
39 | */
40 | public function create()
41 | {
42 | return view('users.create');
43 | }
44 |
45 | /**
46 | * Store a newly created User in storage.
47 | *
48 | * @param CreateUserRequest $request
49 | */
50 | public function store(CreateUserRequest $request)
51 | {
52 | $input = $request->all();
53 | $input['password'] = Hash::make($input['password']);
54 | $user = $this->userRepository->create($input);
55 |
56 | Flash::success('User saved successfully.');
57 |
58 | return redirect(route('users.index'));
59 | }
60 |
61 | /**
62 | * Display the specified User.
63 | *
64 | * @param int $id
65 | */
66 | public function show($id)
67 | {
68 | $user = $this->userRepository->find($id);
69 |
70 | if (empty($user)) {
71 | Flash::error('User not found');
72 |
73 | return redirect(route('users.index'));
74 | }
75 |
76 | return view('users.show')->with('user', $user);
77 | }
78 |
79 | /**
80 | * Show the form for editing the specified User.
81 | *
82 | * @param int $id
83 | */
84 | public function edit($id)
85 | {
86 | $user = $this->userRepository->find($id);
87 |
88 | if (empty($user)) {
89 | Flash::error('User not found');
90 |
91 | return redirect(route('users.index'));
92 | }
93 |
94 | return view('users.edit')->with('user', $user);
95 | }
96 |
97 | /**
98 | * Update the specified User in storage.
99 | *
100 | * @param int $id
101 | * @param UpdateUserRequest $request
102 | */
103 | public function update($id, UpdateUserRequest $request)
104 | {
105 | $user = $this->userRepository->find($id);
106 |
107 | if (empty($user)) {
108 | Flash::error('User not found');
109 |
110 | return redirect(route('users.index'));
111 | }
112 | $input = $request->all();
113 | if (!empty($input['password'])) {
114 | $input['password'] = Hash::make($input['password']);
115 | } else {
116 | unset($input['password']);
117 | }
118 | $user = $this->userRepository->update($input, $id);
119 |
120 | Flash::success('User updated successfully.');
121 |
122 | return redirect(route('users.index'));
123 | }
124 |
125 | /**
126 | * Remove the specified User from storage.
127 | *
128 | * @param int $id
129 | *
130 | * @throws \Exception
131 | */
132 | public function destroy($id)
133 | {
134 | $user = $this->userRepository->find($id);
135 |
136 | if (empty($user)) {
137 | Flash::error('User not found');
138 |
139 | return redirect(route('users.index'));
140 | }
141 |
142 | $this->userRepository->delete($id);
143 |
144 | Flash::success('User deleted successfully.');
145 |
146 | return redirect(route('users.index'));
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/views/scaffold/user/user_controller_without_repository.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "with('users', $users);
29 | }
30 |
31 | /**
32 | * Show the form for creating a new User.
33 | */
34 | public function create()
35 | {
36 | return view('users.create');
37 | }
38 |
39 | /**
40 | * Store a newly created User in storage.
41 | *
42 | * @param CreateUserRequest $request
43 | */
44 | public function store(CreateUserRequest $request)
45 | {
46 | $input = $request->all();
47 | $input['password'] = Hash::make($input['password']);
48 | /** @var User $user */
49 | $user = User::create($input);
50 |
51 | Flash::success('User saved successfully.');
52 |
53 | return redirect(route('users.index'));
54 | }
55 |
56 | /**
57 | * Display the specified User.
58 | *
59 | * @param int $id
60 | */
61 | public function show($id)
62 | {
63 | /** @var User $user */
64 | $user = User::find($id);
65 |
66 | if (empty($user)) {
67 | Flash::error('User not found');
68 |
69 | return redirect(route('users.index'));
70 | }
71 |
72 | return view('users.show')->with('user', $user);
73 | }
74 |
75 | /**
76 | * Show the form for editing the specified User.
77 | *
78 | * @param int $id
79 | */
80 | public function edit($id)
81 | {
82 | /** @var User $user */
83 | $user = User::find($id);
84 |
85 | if (empty($user)) {
86 | Flash::error('User not found');
87 |
88 | return redirect(route('users.index'));
89 | }
90 |
91 | return view('users.edit')->with('user', $user);
92 | }
93 |
94 | /**
95 | * Update the specified User in storage.
96 | *
97 | * @param int $id
98 | * @param UpdateUserRequest $request
99 | */
100 | public function update($id, UpdateUserRequest $request)
101 | {
102 | /** @var User $user */
103 | $user = User::find($id);
104 |
105 | if (empty($user)) {
106 | Flash::error('User not found');
107 |
108 | return redirect(route('users.index'));
109 | }
110 | $input = $request->all();
111 | if (!empty($input['password'])) {
112 | $input['password'] = Hash::make($input['password']);
113 | } else {
114 | unset($input['password']);
115 | }
116 | $user->fill($input);
117 | $user->save();
118 |
119 | Flash::success('User updated successfully.');
120 |
121 | return redirect(route('users.index'));
122 | }
123 |
124 | /**
125 | * Remove the specified User from storage.
126 | *
127 | * @param int $id
128 | *
129 | * @throws \Exception
130 | */
131 | public function destroy($id)
132 | {
133 | /** @var User $user */
134 | $user = User::find($id);
135 |
136 | if (empty($user)) {
137 | Flash::error('User not found');
138 |
139 | return redirect(route('users.index'));
140 | }
141 |
142 | $user->delete();
143 |
144 | Flash::success('User deleted successfully.');
145 |
146 | return redirect(route('users.index'));
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/views/scaffold/user/user_repository.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "fieldSearchable;
34 | }
35 |
36 | /**
37 | * Configure the Model
38 | **/
39 | public function model(): string
40 | {
41 | return User::class;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/views/stubs/app_base_controller.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "json(ResponseUtil::makeResponse($message, $result));
23 | }
24 |
25 | public function sendError($error, $code = 404)
26 | {
27 | return response()->json(ResponseUtil::makeError($error), $code);
28 | }
29 |
30 | public function sendSuccess($message)
31 | {
32 | return response()->json([
33 | 'success' => true,
34 | 'message' => $message
35 | ], 200);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/views/stubs/base_repository.blade.php:
--------------------------------------------------------------------------------
1 | @php
2 | echo "makeModel();
26 | }
27 |
28 | /**
29 | * Get searchable fields array
30 | */
31 | abstract public function getFieldsSearchable(): array;
32 |
33 | /**
34 | * Configure the Model
35 | */
36 | abstract public function model(): string;
37 |
38 | /**
39 | * Make Model instance
40 | *
41 | * @throws \Exception
42 | *
43 | * @return Model
44 | */
45 | public function makeModel()
46 | {
47 | $model = app($this->model());
48 |
49 | if (!$model instanceof Model) {
50 | throw new \Exception("Class {$this->model()} must be an instance of Illuminate\\Database\\Eloquent\\Model");
51 | }
52 |
53 | return $this->model = $model;
54 | }
55 |
56 | /**
57 | * Paginate records for scaffold.
58 | */
59 | public function paginate(int $perPage, array $columns = ['*']): LengthAwarePaginator
60 | {
61 | $query = $this->allQuery();
62 |
63 | return $query->paginate($perPage, $columns);
64 | }
65 |
66 | /**
67 | * Build a query for retrieving all records.
68 | */
69 | public function allQuery(array $search = [], int $skip = null, int $limit = null): Builder
70 | {
71 | $query = $this->model->newQuery();
72 |
73 | if (count($search)) {
74 | foreach($search as $key => $value) {
75 | if (in_array($key, $this->getFieldsSearchable())) {
76 | $query->where($key, $value);
77 | }
78 | }
79 | }
80 |
81 | if (!is_null($skip)) {
82 | $query->skip($skip);
83 | }
84 |
85 | if (!is_null($limit)) {
86 | $query->limit($limit);
87 | }
88 |
89 | return $query;
90 | }
91 |
92 | /**
93 | * Retrieve all records with given filter criteria
94 | */
95 | public function all(array $search = [], int $skip = null, int $limit = null, array $columns = ['*']): Collection
96 | {
97 | $query = $this->allQuery($search, $skip, $limit);
98 |
99 | return $query->get($columns);
100 | }
101 |
102 | /**
103 | * Create model record
104 | */
105 | public function create(array $input): Model
106 | {
107 | $model = $this->model->newInstance($input);
108 |
109 | $model->save();
110 |
111 | return $model;
112 | }
113 |
114 | /**
115 | * Find model record for given id
116 | *
117 | * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|Model|null
118 | */
119 | public function find(int $id, array $columns = ['*'])
120 | {
121 | $query = $this->model->newQuery();
122 |
123 | return $query->find($id, $columns);
124 | }
125 |
126 | /**
127 | * Update model record for given id
128 | *
129 | * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|Model
130 | */
131 | public function update(array $input, int $id)
132 | {
133 | $query = $this->model->newQuery();
134 |
135 | $model = $query->findOrFail($id);
136 |
137 | $model->fill($input);
138 |
139 | $model->save();
140 |
141 | return $model;
142 | }
143 |
144 | /**
145 | * @throws \Exception
146 | *
147 | * @return bool|mixed|null
148 | */
149 | public function delete(int $id)
150 | {
151 | $query = $this->model->newQuery();
152 |
153 | $model = $query->findOrFail($id);
154 |
155 | return $model->delete();
156 | }
157 | }
158 |
--------------------------------------------------------------------------------