├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── composer.json ├── config └── config.php ├── database └── migrations │ ├── 2020_01_01_000001_create_forms_table.php │ └── 2020_01_01_000002_create_form_responses_table.php ├── phpstan.neon.dist └── src ├── Console └── Commands │ ├── MigrateCommand.php │ ├── PublishCommand.php │ └── RollbackCommand.php ├── Models ├── Form.php └── FormResponse.php ├── Providers └── FormsServiceProvider.php └── Traits ├── HasFormResponses.php └── HasForms.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Rinvex Forms Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | This project adheres to [Semantic Versioning](CONTRIBUTING.md). 6 | 7 | 8 | ## [v5.0.1] - 2020-12-25 9 | - Add support for PHP v8 10 | 11 | ## [v5.0.0] - 2020-12-22 12 | - Upgrade to Laravel v8 13 | - Update validation rules 14 | 15 | ## [v4.1.0] - 2020-06-15 16 | - Update validation rules 17 | - Drop using rinvex/laravel-cacheable from core packages for more flexibility 18 | - Caching should be handled on the application layer, not enforced from the core packages 19 | - Drop PHP 7.2 & 7.3 support from travis 20 | 21 | ## [v4.0.6] - 2020-05-30 22 | - Remove default indent size config 23 | - Add strip_tags validation rule to string fields 24 | - Specify events queue 25 | - Explicitly specify relationship attributes 26 | - Add strip_tags validation rule 27 | - Explicitly define relationship name 28 | 29 | ## [v4.0.5] - 2020-04-12 30 | - Fix ServiceProvider registerCommands method compatibility 31 | 32 | ## [v4.0.4] - 2020-04-09 33 | - Tweak artisan command registration 34 | - Reverse commit "Convert database int fields into bigInteger" 35 | - Refactor publish command and allow multiple resource values 36 | 37 | ## [v4.0.3] - 2020-04-04 38 | - Fix namespace issue 39 | 40 | ## [v4.0.2] - 2020-04-04 41 | - Enforce consistent artisan command tag namespacing 42 | - Enforce consistent package namespace 43 | - Drop laravel/helpers usage as it's no longer used 44 | 45 | ## [v4.0.1] - 2020-03-20 46 | - Convert into bigInteger database fields 47 | - Add shortcut -f (force) for artisan publish commands 48 | - Fix migrations path 49 | 50 | ## [v4.0.0] - 2020-03-15 51 | - Upgrade to Laravel v7.1.x & PHP v7.4.x 52 | 53 | ## [v3.0.2] - 2020-03-13 54 | - Tweak TravisCI config 55 | - Add migrations autoload option to the package 56 | - Tweak service provider `publishesResources` 57 | - Remove indirect composer dependency 58 | - Drop using global helpers 59 | - Update StyleCI config 60 | 61 | ## [v3.0.1] - 2019-12-18 62 | - Fix `migrate:reset` args as it doesn't accept --step 63 | 64 | ## [v3.0.0] - 2019-09-23 65 | - Upgrade to Laravel v6 and update dependencies 66 | 67 | ## [v2.1.1] - 2019-06-03 68 | - Enforce latest composer package versions 69 | 70 | ## [v2.1.0] - 2019-06-02 71 | - Update composer deps 72 | - Drop PHP 7.1 travis test 73 | - Refactor migrations and artisan commands, and tweak service provider publishes functionality 74 | 75 | ## [v2.0.0] - 2019-03-03 76 | - Rename environment variable QUEUE_DRIVER to QUEUE_CONNECTION 77 | - Require PHP 7.2 & Laravel 5.8 78 | - Apply PHPUnit 8 updates 79 | - Tweak and simplify FormRequest validations 80 | 81 | ## [v1.0.2] - 2018-12-22 82 | - Update composer dependencies 83 | - Add PHP 7.3 support to travis 84 | - Fix MySQL / PostgreSQL json column compatibility 85 | 86 | ## [v1.0.1] - 2018-10-05 87 | - Fix wrong composer package version constraints 88 | 89 | ## [v1.0.0] - 2018-10-01 90 | - Enforce Consistency 91 | - Support Laravel 5.7+ 92 | - Rename package to rinvex/laravel-forms 93 | 94 | ## v0.0.1 - 2018-09-22 95 | - Tag first release 96 | 97 | [v5.0.1]: https://github.com/rinvex/laravel-forms/compare/v5.0.0...v5.0.1 98 | [v5.0.0]: https://github.com/rinvex/laravel-forms/compare/v4.1.0...v5.0.0 99 | [v4.1.0]: https://github.com/rinvex/laravel-forms/compare/v4.0.6...v4.1.0 100 | [v4.0.6]: https://github.com/rinvex/laravel-forms/compare/v4.0.5...v4.0.6 101 | [v4.0.5]: https://github.com/rinvex/laravel-forms/compare/v4.0.4...v4.0.5 102 | [v4.0.4]: https://github.com/rinvex/laravel-forms/compare/v4.0.3...v4.0.4 103 | [v4.0.3]: https://github.com/rinvex/laravel-forms/compare/v4.0.2...v4.0.3 104 | [v4.0.2]: https://github.com/rinvex/laravel-forms/compare/v4.0.1...v4.0.2 105 | [v4.0.1]: https://github.com/rinvex/laravel-forms/compare/v4.0.0...v4.0.1 106 | [v4.0.0]: https://github.com/rinvex/laravel-forms/compare/v3.0.2...v4.0.0 107 | [v3.0.2]: https://github.com/rinvex/laravel-forms/compare/v3.0.1...v3.0.2 108 | [v3.0.1]: https://github.com/rinvex/laravel-forms/compare/v3.0.0...v3.0.1 109 | [v3.0.0]: https://github.com/rinvex/laravel-forms/compare/v2.1.1...v3.0.0 110 | [v2.1.1]: https://github.com/rinvex/laravel-forms/compare/v2.1.0...v2.1.1 111 | [v2.1.0]: https://github.com/rinvex/laravel-forms/compare/v2.0.0...v2.1.0 112 | [v2.0.0]: https://github.com/rinvex/laravel-forms/compare/v1.0.2...v2.0.0 113 | [v1.0.2]: https://github.com/rinvex/laravel-forms/compare/v1.0.1...v1.0.2 114 | [v1.0.1]: https://github.com/rinvex/laravel-forms/compare/v1.0.0...v1.0.1 115 | [v1.0.0]: https://github.com/rinvex/laravel-forms/compare/v0.0.1...v1.0.0 116 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by forming the project team at [help@rinvex.com](mailto:help@rinvex.com). All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ 75 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution Guide 2 | 3 | This project adheres to the following standards and practices. 4 | 5 | 6 | ## Versioning 7 | 8 | This project is versioned under the [Semantic Versioning](http://semver.org/) guidelines as much as possible. 9 | 10 | Releases will be numbered with the following format: 11 | 12 | - `..` 13 | - `..` 14 | 15 | And constructed with the following guidelines: 16 | 17 | - Breaking backward compatibility bumps the major and resets the minor and patch. 18 | - New additions without breaking backward compatibility bump the minor and reset the patch. 19 | - Bug fixes and misc changes bump the patch. 20 | 21 | 22 | ## Pull Requests 23 | 24 | The pull request process differs for new features and bugs. 25 | 26 | Pull requests for bugs may be sent without creating any proposal issue. If you believe that you know of a solution for a bug that has been filed, please leave a comment detailing your proposed fix or create a pull request with the fix mentioning that issue id. 27 | 28 | 29 | ## Coding Standards 30 | 31 | This project follows the FIG PHP Standards Recommendations compliant with the [PSR-1: Basic Coding Standard](http://www.php-fig.org/psr/psr-1/), [PSR-2: Coding Style Guide](http://www.php-fig.org/psr/psr-2/) and [PSR-4: Autoloader](http://www.php-fig.org/psr/psr-4/) to ensure a high level of interoperability between shared PHP code. If you notice any compliance oversights, please send a patch via pull request. 32 | 33 | 34 | ## Feature Requests 35 | 36 | If you have a proposal or a feature request, you may create an issue with `[Proposal]` in the title. 37 | 38 | The proposal should also describe the new feature, as well as implementation ideas. The proposal will then be reviewed and either approved or denied. Once a proposal is approved, a pull request may be created implementing the new feature. 39 | 40 | 41 | ## Git Flow 42 | 43 | This project follows [Git-Flow](http://nvie.com/posts/a-successful-git-branching-model/), and as such has `master` (latest stable releases), `develop` (latest WIP development) and X.Y support branches (when there's multiple major versions). 44 | 45 | Accordingly all pull requests MUST be sent to the `develop` branch. 46 | 47 | > **Note:** Pull requests which do not follow these guidelines will be closed without any further notice. 48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016-2021, Rinvex LLC, 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rinvex Forms 2 | 3 | ⚠️ This package is abandoned and no longer maintained. No replacement package was suggested. ⚠️ 4 | 5 | 👉 If you are interested to step on as the main maintainer of this package, please [reach out to me](https://twitter.com/omranic)! 6 | 7 | --- 8 | 9 | 10 | **Rinvex Forms** is a dynamic form builder for Laravel, it's like the missing gem, the possibilities of using it are endless! With flexible API and powerful features you can build almost every kind of complex form with ease. 11 | 12 | [![Packagist](https://img.shields.io/packagist/v/rinvex/laravel-forms.svg?label=Packagist&style=flat-square)](https://packagist.org/packages/rinvex/laravel-forms) 13 | [![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/rinvex/laravel-forms.svg?label=Scrutinizer&style=flat-square)](https://scrutinizer-ci.com/g/rinvex/laravel-forms/) 14 | [![Travis](https://img.shields.io/travis/rinvex/laravel-forms.svg?label=TravisCI&style=flat-square)](https://travis-ci.org/rinvex/laravel-forms) 15 | [![StyleCI](https://styleci.io/repos/138185596/shield)](https://styleci.io/repos/138185596) 16 | [![License](https://img.shields.io/packagist/l/rinvex/laravel-forms.svg?label=License&style=flat-square)](https://github.com/rinvex/laravel-forms/blob/develop/LICENSE) 17 | 18 | 19 | ## Installation 20 | 21 | 1. Install the package via composer: 22 | ```shell 23 | composer require rinvex/laravel-forms 24 | ``` 25 | 26 | 2. Publish resources (migrations and config files): 27 | ```shell 28 | php artisan rinvex:publish:forms 29 | ``` 30 | 31 | 3. Execute migrations via the following command: 32 | ```shell 33 | php artisan rinvex:migrate:forms 34 | ``` 35 | 36 | 4. Done! 37 | 38 | 39 | ## Warning 40 | 41 | ⚠️ This documentation ins INCOMPLETE! Please use on your own, or wait until it's ready! ⚠️ 42 | 43 | ## Usage 44 | 45 | To add forms to other entities, simply use `\Rinvex\Forms\Traits\HasForms` trait in the model. Example: you may have `Event` model, that requires registration form, then confirmation form, and every form fields differs from an event to another, in this case you can attach `From` models to your `Event` models using that trait. 46 | 47 | To add form responses to users, simply use `\Rinvex\Forms\Traits\HasFormResponses` trait in the model. Example: you most probably will allow your users to fill forms while signed in, in such case you need to attach their responses to their accounts for later retrieval, and you can do so using that trait. This will attach `FormResponse` models to your user models `User`. 48 | 49 | ### Manage your forms 50 | 51 | ```php 52 | // Get instance of your parent model (ex. `Event`) 53 | $event = new \App\Models\Event::find(1); 54 | 55 | // Create multiple new forms 56 | $event->forms()->createMany([ 57 | [...], 58 | [...], 59 | [...], 60 | ]); 61 | 62 | // Find an existing form 63 | $form = app('rinvex.forms.form')->find(1); 64 | 65 | // Update an existing form 66 | $form->update([ 67 | 'name' => 'Contact Us', 68 | ]); 69 | 70 | // Delete form 71 | $form->delete(); 72 | 73 | // Alternative way of form deletion 74 | $event->forms()->where('id', 123)->first()->delete(); 75 | 76 | // Get attached forms collection 77 | $event->forms; 78 | 79 | // Get attached forms query builder 80 | $event->forms(); 81 | ``` 82 | 83 | 84 | ## Changelog 85 | 86 | Refer to the [Changelog](CHANGELOG.md) for a full history of the project. 87 | 88 | 89 | ## Support 90 | 91 | The following support channels are available at your fingertips: 92 | 93 | - [Chat on Slack](https://bit.ly/rinvex-slack) 94 | - [Help on Email](mailto:help@rinvex.com) 95 | - [Follow on Twitter](https://twitter.com/rinvex) 96 | 97 | 98 | ## Contributing & Protocols 99 | 100 | Thank you for considering contributing to this project! The contribution guide can be found in [CONTRIBUTING.md](CONTRIBUTING.md). 101 | 102 | Bug reports, feature requests, and pull requests are very welcome. 103 | 104 | - [Versioning](CONTRIBUTING.md#versioning) 105 | - [Pull Requests](CONTRIBUTING.md#pull-requests) 106 | - [Coding Standards](CONTRIBUTING.md#coding-standards) 107 | - [Feature Requests](CONTRIBUTING.md#feature-requests) 108 | - [Git Flow](CONTRIBUTING.md#git-flow) 109 | 110 | 111 | ## Security Vulnerabilities 112 | 113 | If you discover a security vulnerability within this project, please send an e-mail to [help@rinvex.com](help@rinvex.com). All security vulnerabilities will be promptly formed. 114 | 115 | 116 | ## About Rinvex 117 | 118 | Rinvex is a software solutions startup, specialized in integrated enterprise solutions for SMEs established in Alexandria, Egypt since June 2016. We believe that our drive The Value, The Reach, and The Impact is what differentiates us and unleash the endless possibilities of our philosophy through the power of software. We like to call it Innovation At The Speed Of Life. That’s how we do our share of advancing humanity. 119 | 120 | 121 | ## License 122 | 123 | This software is released under [The MIT License (MIT)](LICENSE). 124 | 125 | (c) 2016-2021 Rinvex LLC, Some rights reserved. 126 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rinvex/laravel-forms", 3 | "description": "Rinvex Forms is a dynamic form builder for Laravel, it's like the missing gem, the possibilities of using it are endless! With flexible API and powerful features you can build almost every kind of complex form with ease.", 4 | "type": "library", 5 | "keywords": [ 6 | "form", 7 | "model", 8 | "rinvex", 9 | "laravel", 10 | "eloquent", 11 | "submission", 12 | "registration", 13 | "booking", 14 | "fields", 15 | "event", 16 | "forms" 17 | ], 18 | "license": "MIT", 19 | "homepage": "https://rinvex.com", 20 | "support": { 21 | "email": "help@rinvex.com", 22 | "issues": "https://github.com/rinvex/laravel-forms/issues", 23 | "source": "https://github.com/rinvex/laravel-forms", 24 | "docs": "https://github.com/rinvex/laravel-forms/blob/master/README.md" 25 | }, 26 | "authors": [ 27 | { 28 | "name": "Rinvex LLC", 29 | "homepage": "https://rinvex.com", 30 | "email": "help@rinvex.com" 31 | }, 32 | { 33 | "name": "Abdelrahman Omran", 34 | "homepage": "https://omranic.com", 35 | "email": "me@omranic.com", 36 | "role": "Project Lead" 37 | }, 38 | { 39 | "name": "The Generous Laravel Community", 40 | "homepage": "https://github.com/rinvex/laravel-forms/contributors" 41 | } 42 | ], 43 | "require": { 44 | "php": "^7.4.0 || ^8.0.0", 45 | "illuminate/console": "^8.0.0 || ^9.0.0", 46 | "illuminate/database": "^8.0.0 || ^9.0.0", 47 | "illuminate/support": "^8.0.0 || ^9.0.0", 48 | "jackpopp/geodistance": "^1.2.0", 49 | "propaganistas/laravel-phone": "^4.2.0", 50 | "rinvex/countries": "^7.0.0", 51 | "rinvex/languages": "^5.0.0", 52 | "rinvex/laravel-support": "^5.0.0" 53 | }, 54 | "require-dev": { 55 | "codedungeon/phpunit-result-printer": "^0.30.0", 56 | "illuminate/container": "^8.0.0 || ^9.0.0", 57 | "phpunit/phpunit": "^9.5.0" 58 | }, 59 | "autoload": { 60 | "psr-4": { 61 | "Rinvex\\Forms\\": "src/" 62 | } 63 | }, 64 | "autoload-dev": { 65 | "psr-4": { 66 | "Rinvex\\Forms\\Tests\\": "tests" 67 | } 68 | }, 69 | "scripts": { 70 | "test": "vendor/bin/phpunit" 71 | }, 72 | "config": { 73 | "sort-packages": true, 74 | "preferred-install": "dist", 75 | "optimize-autoloader": true 76 | }, 77 | "extra": { 78 | "laravel": { 79 | "providers": [ 80 | "Rinvex\\Forms\\Providers\\FormsServiceProvider" 81 | ] 82 | } 83 | }, 84 | "minimum-stability": "dev", 85 | "prefer-stable": true 86 | } 87 | -------------------------------------------------------------------------------- /config/config.php: -------------------------------------------------------------------------------- 1 | true, 9 | 10 | // Forms Database Tables 11 | 'tables' => [ 12 | 'forms' => 'forms', 13 | 'form_responses' => 'form_responses', 14 | ], 15 | 16 | // Forms Models 17 | 'models' => [ 18 | 'form' => \Rinvex\Forms\Models\Form::class, 19 | 'form_response' => \Rinvex\Forms\Models\FormResponse::class, 20 | ], 21 | 22 | ]; 23 | -------------------------------------------------------------------------------- /database/migrations/2020_01_01_000001_create_forms_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 21 | $table->nullableMorphs('entity'); 22 | $table->string('slug'); 23 | $table->{$this->jsonable()}('name'); 24 | $table->{$this->jsonable()}('description')->nullable(); 25 | $table->{$this->jsonable()}('content'); 26 | $table->{$this->jsonable()}('actions')->nullable(); 27 | $table->{$this->jsonable()}('submission')->nullable(); 28 | $table->boolean('is_active')->default(false); 29 | $table->boolean('is_public')->default(false); 30 | $table->timestamps(); 31 | $table->softDeletes(); 32 | 33 | // Indexes 34 | $table->unique('slug'); 35 | }); 36 | } 37 | 38 | /** 39 | * Reverse the migrations. 40 | * 41 | * @return void 42 | */ 43 | public function down() 44 | { 45 | Schema::dropIfExists(config('rinvex.forms.tables.forms')); 46 | } 47 | 48 | /** 49 | * Get jsonable column data type. 50 | * 51 | * @return string 52 | */ 53 | protected function jsonable(): string 54 | { 55 | $driverName = DB::connection()->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME); 56 | $dbVersion = DB::connection()->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION); 57 | $isOldVersion = version_compare($dbVersion, '5.7.8', 'lt'); 58 | 59 | return $driverName === 'mysql' && $isOldVersion ? 'text' : 'json'; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /database/migrations/2020_01_01_000002_create_form_responses_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 21 | $table->string('unique_identifier')->nullable(); 22 | $table->{$this->jsonable()}('content'); 23 | $table->integer('form_id')->unsigned(); 24 | $table->nullableMorphs('user'); 25 | $table->timestamps(); 26 | $table->softDeletes(); 27 | 28 | // Indexes 29 | $table->foreign('form_id')->references('id')->on(config('rinvex.forms.tables.forms')) 30 | ->onDelete('cascade')->onUpdate('cascade'); 31 | }); 32 | } 33 | 34 | /** 35 | * Reverse the migrations. 36 | * 37 | * @return void 38 | */ 39 | public function down() 40 | { 41 | Schema::dropIfExists(config('rinvex.forms.tables.form_responses')); 42 | } 43 | 44 | /** 45 | * Get jsonable column data type. 46 | * 47 | * @return string 48 | */ 49 | protected function jsonable(): string 50 | { 51 | $driverName = DB::connection()->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME); 52 | $dbVersion = DB::connection()->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION); 53 | $isOldVersion = version_compare($dbVersion, '5.7.8', 'lt'); 54 | 55 | return $driverName === 'mysql' && $isOldVersion ? 'text' : 'json'; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /phpstan.neon.dist: -------------------------------------------------------------------------------- 1 | includes: 2 | - ./vendor/nunomaduro/larastan/extension.neon 3 | parameters: 4 | level: 5 5 | paths: 6 | - src 7 | -------------------------------------------------------------------------------- /src/Console/Commands/MigrateCommand.php: -------------------------------------------------------------------------------- 1 | alert($this->description); 33 | 34 | $path = config('rinvex.forms.autoload_migrations') ? 35 | 'vendor/rinvex/laravel-forms/database/migrations' : 36 | 'database/migrations/rinvex/laravel-forms'; 37 | 38 | if (file_exists($path)) { 39 | $this->call('migrate', [ 40 | '--step' => true, 41 | '--path' => $path, 42 | '--force' => $this->option('force'), 43 | ]); 44 | } else { 45 | $this->warn('No migrations found! Consider publish them first: php artisan rinvex:publish:forms'); 46 | } 47 | 48 | $this->line(''); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Console/Commands/PublishCommand.php: -------------------------------------------------------------------------------- 1 | alert($this->description); 33 | 34 | collect($this->option('resource') ?: ['config', 'migrations'])->each(function ($resource) { 35 | $this->call('vendor:publish', ['--tag' => "rinvex/forms::{$resource}", '--force' => $this->option('force')]); 36 | }); 37 | 38 | $this->line(''); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Console/Commands/RollbackCommand.php: -------------------------------------------------------------------------------- 1 | alert($this->description); 33 | 34 | $path = config('rinvex.forms.autoload_migrations') ? 35 | 'vendor/rinvex/laravel-forms/database/migrations' : 36 | 'database/migrations/rinvex/laravel-forms'; 37 | 38 | if (file_exists($path)) { 39 | $this->call('migrate:reset', [ 40 | '--path' => $path, 41 | '--force' => $this->option('force'), 42 | ]); 43 | } else { 44 | $this->warn('No migrations found! Consider publish them first: php artisan rinvex:publish:forms'); 45 | } 46 | 47 | $this->line(''); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Models/Form.php: -------------------------------------------------------------------------------- 1 | 'integer', 75 | 'entity_type' => 'string', 76 | 'slug' => 'string', 77 | 'name' => 'string', 78 | 'description' => 'string', 79 | 'content' => 'json', 80 | 'actions' => 'json', 81 | 'submission' => 'json', 82 | 'is_active' => 'boolean', 83 | 'is_public' => 'boolean', 84 | 'deleted_at' => 'datetime', 85 | ]; 86 | 87 | /** 88 | * {@inheritdoc} 89 | */ 90 | protected $observables = [ 91 | 'validating', 92 | 'validated', 93 | ]; 94 | 95 | /** 96 | * The attributes that are translatable. 97 | * 98 | * @var array 99 | */ 100 | public $translatable = [ 101 | 'name', 102 | 'description', 103 | ]; 104 | 105 | /** 106 | * The default rules that the model will validate against. 107 | * 108 | * @var array 109 | */ 110 | protected $rules = [ 111 | 'entity_id' => 'nullable|integer', 112 | 'entity_type' => 'nullable|string|strip_tags|max:150', 113 | 'slug' => 'required|alpha_dash|max:150', 114 | 'name' => 'required|string|strip_tags|max:150', 115 | 'description' => 'nullable|string|max:32768', 116 | 'content' => 'required|array', 117 | 'actions' => 'required|array', 118 | 'submission' => 'required|array', 119 | 'is_active' => 'sometimes|boolean', 120 | 'is_public' => 'sometimes|boolean', 121 | ]; 122 | 123 | /** 124 | * Whether the model should throw a 125 | * ValidationException if it fails validation. 126 | * 127 | * @var bool 128 | */ 129 | protected $throwValidationExceptions = true; 130 | 131 | /** 132 | * Create a new Eloquent model instance. 133 | * 134 | * @param array $attributes 135 | */ 136 | public function __construct(array $attributes = []) 137 | { 138 | parent::__construct($attributes); 139 | 140 | $this->setTable(config('rinvex.forms.tables.forms')); 141 | } 142 | 143 | /** 144 | * {@inheritdoc} 145 | */ 146 | protected static function boot() 147 | { 148 | parent::boot(); 149 | 150 | static::deleted(function (self $model) { 151 | $model->responses()->delete(); 152 | }); 153 | } 154 | 155 | /** 156 | * Get the options for generating the slug. 157 | * 158 | * @return \Spatie\Sluggable\SlugOptions 159 | */ 160 | public function getSlugOptions(): SlugOptions 161 | { 162 | return SlugOptions::create() 163 | ->doNotGenerateSlugsOnUpdate() 164 | ->generateSlugsFrom('name') 165 | ->saveSlugsTo('slug'); 166 | } 167 | 168 | /** 169 | * The form may have many responses. 170 | * 171 | * @return \Illuminate\Database\Eloquent\Relations\HasMany 172 | */ 173 | public function responses(): HasMany 174 | { 175 | return $this->hasMany(config('rinvex.forms.models.form_response'), 'form_id', 'id'); 176 | } 177 | 178 | /** 179 | * Get the owner model of the form. 180 | * 181 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo 182 | */ 183 | public function entity(): MorphTo 184 | { 185 | return $this->morphTo('entity', 'entity_type', 'entity_id', 'id'); 186 | } 187 | 188 | /** 189 | * Activate the form. 190 | * 191 | * @return $this 192 | */ 193 | public function activate() 194 | { 195 | $this->update(['is_active' => true]); 196 | 197 | return $this; 198 | } 199 | 200 | /** 201 | * Deactivate the form. 202 | * 203 | * @return $this 204 | */ 205 | public function deactivate() 206 | { 207 | $this->update(['is_active' => false]); 208 | 209 | return $this; 210 | } 211 | } 212 | -------------------------------------------------------------------------------- /src/Models/FormResponse.php: -------------------------------------------------------------------------------- 1 | 'string', 55 | 'content' => 'json', 56 | 'form_id' => 'integer', 57 | 'user_id' => 'integer', 58 | 'user_type' => 'string', 59 | 'deleted_at' => 'datetime', 60 | ]; 61 | 62 | /** 63 | * {@inheritdoc} 64 | */ 65 | protected $observables = [ 66 | 'validating', 67 | 'validated', 68 | ]; 69 | 70 | /** 71 | * The default rules that the model will validate against. 72 | * 73 | * @var array 74 | */ 75 | protected $rules = []; 76 | 77 | /** 78 | * Whether the model should throw a 79 | * ValidationException if it fails validation. 80 | * 81 | * @var bool 82 | */ 83 | protected $throwValidationExceptions = true; 84 | 85 | /** 86 | * Create a new Eloquent model instance. 87 | * 88 | * @param array $attributes 89 | */ 90 | public function __construct(array $attributes = []) 91 | { 92 | parent::__construct($attributes); 93 | 94 | $this->setTable(config('rinvex.forms.tables.form_responses')); 95 | $this->setRules([ 96 | 'unique_identifier' => 'nullable|string|strip_tags|max:150', 97 | 'content' => 'required|array', 98 | 'form_id' => 'required|integer|exists:'.config('rinvex.forms.tables.forms').',id', 99 | 'user_id' => 'nullable|integer', 100 | 'user_type' => 'nullable|string|strip_tags|max:150', 101 | ]); 102 | } 103 | 104 | /** 105 | * Get the form response user. 106 | * 107 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo 108 | */ 109 | public function user() 110 | { 111 | return $this->morphTo('user', 'user_type', 'user_id', 'id'); 112 | } 113 | 114 | /** 115 | * Get form responses of the given user. 116 | * 117 | * @param \Illuminate\Database\Eloquent\Builder $builder 118 | * @param \Illuminate\Database\Eloquent\Model $user 119 | * 120 | * @return \Illuminate\Database\Eloquent\Builder 121 | */ 122 | public function scopeOfUser(Builder $builder, Model $user): Builder 123 | { 124 | return $builder->where('user_type', $user->getMorphClass())->where('user_id', $user->getKey()); 125 | } 126 | 127 | /** 128 | * The form response always belongs to a form. 129 | * 130 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo 131 | */ 132 | public function form(): BelongsTo 133 | { 134 | return $this->belongsTo(config('rinvex.forms.models.form'), 'form_id', 'id', 'form'); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/Providers/FormsServiceProvider.php: -------------------------------------------------------------------------------- 1 | 'command.rinvex.forms.migrate', 26 | PublishCommand::class => 'command.rinvex.forms.publish', 27 | RollbackCommand::class => 'command.rinvex.forms.rollback', 28 | ]; 29 | 30 | /** 31 | * {@inheritdoc} 32 | */ 33 | public function register() 34 | { 35 | // Merge config 36 | $this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'rinvex.forms'); 37 | 38 | // Bind eloquent models to IoC container 39 | $this->app->singleton('rinvex.forms.form', $formModel = $this->app['config']['rinvex.forms.models.form']); 40 | $formModel === Form::class || $this->app->alias('rinvex.forms.form', Form::class); 41 | 42 | $this->app->singleton('rinvex.forms.form_response', $formModel = $this->app['config']['rinvex.forms.models.form_response']); 43 | $formModel === FormResponse::class || $this->app->alias('rinvex.forms.form_response', FormResponse::class); 44 | 45 | // Register console commands 46 | $this->registerCommands($this->commands); 47 | } 48 | 49 | /** 50 | * {@inheritdoc} 51 | */ 52 | public function boot() 53 | { 54 | // Publish Resources 55 | $this->publishesConfig('rinvex/laravel-forms'); 56 | $this->publishesMigrations('rinvex/laravel-forms'); 57 | ! $this->autoloadMigrations('rinvex/laravel-forms') || $this->loadMigrationsFrom(__DIR__.'/../../database/migrations'); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Traits/HasFormResponses.php: -------------------------------------------------------------------------------- 1 | formResponses()->delete(); 42 | }); 43 | } 44 | 45 | /** 46 | * Get all attached form responses to the model. 47 | * 48 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany 49 | */ 50 | public function formResponses(): MorphMany 51 | { 52 | return $this->morphMany(config('rinvex.forms.models.form_response'), 'user'); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Traits/HasForms.php: -------------------------------------------------------------------------------- 1 | forms()->delete(); 42 | }); 43 | } 44 | 45 | /** 46 | * Get all attached forms to the model. 47 | * 48 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany 49 | */ 50 | public function forms(): MorphMany 51 | { 52 | return $this->morphMany(config('rinvex.forms.models.form'), 'entity'); 53 | } 54 | } 55 | --------------------------------------------------------------------------------