├── .styleci.yml ├── Laravel Overflow.png ├── config └── config.php ├── CHANGELOG.md ├── src ├── Models │ └── TestModel.php ├── LaravelOverflowFacade.php ├── LaravelOverflow.php ├── LaravelOverflowServiceProvider.php └── Overflowable.php ├── all-contributorsrc.json ├── database └── migrations │ └── create_test_models_table.php ├── LICENSE.md ├── .phpunit.result.cache ├── composer.json ├── .github └── workflows │ └── run-tests.yml ├── .all-contributorsrc ├── CONTRIBUTING.md └── README.md /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel 2 | 3 | disabled: 4 | - single_class_element_per_statement 5 | -------------------------------------------------------------------------------- /Laravel Overflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CraftLogan/Laravel-Overflow/HEAD/Laravel Overflow.png -------------------------------------------------------------------------------- /config/config.php: -------------------------------------------------------------------------------- 1 | properties); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/LaravelOverflowFacade.php: -------------------------------------------------------------------------------- 1 | -orange.svg?style=flat-square)](#contributors)", 6 | "contributorTemplate": "\">\" width=\"<%= options.imageSize %>px;\" alt=\"\"/>
<%= contributor.name %>
", 7 | "skipCi": "true", 8 | "contributors": [] 9 | } 10 | -------------------------------------------------------------------------------- /database/migrations/create_test_models_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 14 | $table->string('name'); 15 | $table->text('description'); 16 | $table->text('properties'); 17 | $table->timestamps(); 18 | }); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/LaravelOverflow.php: -------------------------------------------------------------------------------- 1 | request = $request; 20 | $this->model = $model; 21 | $this->overflow_column = $overflow_column; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/LaravelOverflowServiceProvider.php: -------------------------------------------------------------------------------- 1 | overflow(); 19 | }); 20 | 21 | Request::macro('allWithOverflow', function (Model $model, $properties = "properties") { 22 | $overflow = new LaravelOverflow($this, $model, $properties); 23 | return $overflow->allWithOverflow(); 24 | }); 25 | } 26 | 27 | /** 28 | * Register the application services. 29 | */ 30 | public function register() 31 | { 32 | // 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Logan H. Craft 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. -------------------------------------------------------------------------------- /src/Overflowable.php: -------------------------------------------------------------------------------- 1 | overflow_column] = $this->overflow(); 11 | return array_merge($properties, $this->getColumns()); 12 | } 13 | 14 | public function getColumns() 15 | { 16 | $columnNames = $this->getColumnNames(); 17 | $attributes = array_intersect_key($this->request->all(), $columnNames); 18 | return $attributes; 19 | } 20 | 21 | public function overflow() 22 | { 23 | $columnNames = $this->getColumnNames(); 24 | $attributes = array_diff_key($this->request->all(), $columnNames); 25 | $attributes = json_encode($attributes); 26 | return $attributes; 27 | } 28 | 29 | public function getTableColumns() 30 | { 31 | return Schema::getColumnListing($this->model->getTable()); 32 | } 33 | 34 | public function getColumnNames() 35 | { 36 | $columnNames = $this->getTableColumns(); 37 | $columnNames = array_fill_keys($columnNames, ""); 38 | return $columnNames; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /.phpunit.result.cache: -------------------------------------------------------------------------------- 1 | C:37:"PHPUnit\Runner\DefaultTestResultCache":1584:{a:2:{s:7:"defects";a:5:{s:92:"CraftLogan\LaravelOverflow\Tests\ExampleTest::it_can_add_extra_properties_with_create_method";i:4;s:96:"CraftLogan\LaravelOverflow\Tests\ExampleTest::it_can_add_extra_properties_using_model_attributes";i:4;s:70:"CraftLogan\LaravelOverflow\Tests\ExampleTest::it_can_get_table_columns";i:5;s:93:"CraftLogan\LaravelOverflow\Tests\OverflowTest::it_can_add_extra_properties_with_macro_request";i:4;s:71:"CraftLogan\LaravelOverflow\Tests\OverflowTest::it_can_get_table_columns";i:4;}s:5:"times";a:10:{s:92:"CraftLogan\LaravelOverflow\Tests\ExampleTest::it_can_add_extra_properties_with_create_method";d:0.01;s:96:"CraftLogan\LaravelOverflow\Tests\ExampleTest::it_can_add_extra_properties_using_model_attributes";d:0.003;s:94:"CraftLogan\LaravelOverflow\Tests\ExampleTest::it_can_add_multiple_extra_properties_to_overflow";d:0.086;s:70:"CraftLogan\LaravelOverflow\Tests\ExampleTest::it_can_get_table_columns";d:0.003;s:95:"CraftLogan\LaravelOverflow\Tests\OverflowTest::it_can_add_multiple_extra_properties_to_overflow";d:0.09;s:93:"CraftLogan\LaravelOverflow\Tests\OverflowTest::it_can_add_extra_properties_with_create_method";d:0.011;s:71:"CraftLogan\LaravelOverflow\Tests\OverflowTest::it_can_get_table_columns";d:0.093;s:97:"CraftLogan\LaravelOverflow\Tests\OverflowTest::it_can_add_extra_properties_using_model_attributes";d:0.005;s:93:"CraftLogan\LaravelOverflow\Tests\OverflowTest::it_can_add_extra_properties_with_macro_request";d:0.01;s:99:"CraftLogan\LaravelOverflow\Tests\OverflowTest::it_can_add_extra_properties_with_macro_create_method";d:0.006;}}} -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "craftlogan/laravel-overflow", 3 | "description": "The Laravel Overflow package will allow adding an overflow column to a form request easily. Use this package to make it easy to store overflow request values in a JSON or Text column on a database table:)", 4 | "keywords": [ 5 | "craftlogan", 6 | "laravel-overflow" 7 | ], 8 | "homepage": "https://github.com/craftlogan/laravel-overflow", 9 | "license": "MIT", 10 | "type": "library", 11 | "authors": [ 12 | { 13 | "name": "Logan H. Craft", 14 | "email": "craftlogan@gmail.com", 15 | "role": "Developer" 16 | } 17 | ], 18 | "require": { 19 | "php": "^8.0", 20 | "illuminate/support": "^6|^7|^8" 21 | }, 22 | "require-dev": { 23 | "orchestra/testbench": "^4.0|^5.0|^6.0", 24 | "phpunit/phpunit": "^8.0|^9.0" 25 | }, 26 | "autoload": { 27 | "psr-4": { 28 | "CraftLogan\\LaravelOverflow\\": "src" 29 | } 30 | }, 31 | "autoload-dev": { 32 | "psr-4": { 33 | "CraftLogan\\LaravelOverflow\\Tests\\": "tests" 34 | } 35 | }, 36 | "scripts": { 37 | "test": "vendor/bin/phpunit", 38 | "test-coverage": "vendor/bin/phpunit --coverage-html coverage" 39 | 40 | }, 41 | "config": { 42 | "sort-packages": true 43 | }, 44 | "extra": { 45 | "laravel": { 46 | "providers": [ 47 | "CraftLogan\\LaravelOverflow\\LaravelOverflowServiceProvider" 48 | ], 49 | "aliases": { 50 | "LaravelOverflow": "CraftLogan\\LaravelOverflow\\LaravelOverflowFacade" 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /.github/workflows/run-tests.yml: -------------------------------------------------------------------------------- 1 | name: run-tests 2 | 3 | on: 4 | push: 5 | schedule: 6 | - cron: '0 0 * * *' 7 | 8 | jobs: 9 | test: 10 | 11 | runs-on: ubuntu-latest 12 | strategy: 13 | fail-fast: true 14 | matrix: 15 | php: [8.0, 7.4, 7.3] 16 | laravel: [8.*, 7.*, 6.*] 17 | dependency-version: [prefer-lowest, prefer-stable] 18 | include: 19 | - laravel: 8.* 20 | testbench: 6.* 21 | - laravel: 7.* 22 | testbench: 5.* 23 | - laravel: 6.* 24 | testbench: 4.* 25 | 26 | name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} 27 | 28 | steps: 29 | - name: Checkout code 30 | uses: actions/checkout@v1 31 | 32 | - name: Cache dependencies 33 | uses: actions/cache@v1 34 | with: 35 | path: ~/.composer/cache/files 36 | key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} 37 | 38 | - name: Setup PHP 39 | uses: shivammathur/setup-php@v2 40 | with: 41 | php-version: ${{ matrix.php }} 42 | extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick 43 | coverage: none 44 | 45 | - name: Install dependencies 46 | run: | 47 | composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update 48 | composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest 49 | - name: Execute tests 50 | run: vendor/bin/phpunit 51 | 52 | -------------------------------------------------------------------------------- /.all-contributorsrc: -------------------------------------------------------------------------------- 1 | { 2 | "files": [ 3 | "README.md" 4 | ], 5 | "imageSize": 100, 6 | "commit": false, 7 | "contributors": [ 8 | { 9 | "login": "CraftLogan", 10 | "name": "Logan H. Craft", 11 | "avatar_url": "https://avatars0.githubusercontent.com/u/10950466?v=4", 12 | "profile": "https://logancraft.dev", 13 | "contributions": [ 14 | "code", 15 | "doc" 16 | ] 17 | }, 18 | { 19 | "login": "DanielGilB", 20 | "name": "Daniel", 21 | "avatar_url": "https://avatars0.githubusercontent.com/u/32772927?v=4", 22 | "profile": "https://github.com/DanielGilB", 23 | "contributions": [ 24 | "code" 25 | ] 26 | }, 27 | { 28 | "login": "laravelnews", 29 | "name": "Laravel News", 30 | "avatar_url": "https://avatars0.githubusercontent.com/u/6818566?v=4", 31 | "profile": "https://laravel-news.com", 32 | "contributions": [ 33 | "blog" 34 | ] 35 | }, 36 | { 37 | "login": "paulredmond", 38 | "name": "Paul Redmond", 39 | "avatar_url": "https://avatars3.githubusercontent.com/u/177773?v=4", 40 | "profile": "https://twitter.com/paulredmond", 41 | "contributions": [ 42 | "blog" 43 | ] 44 | }, 45 | { 46 | "login": "parnissolle", 47 | "name": "Pierre Arnissolle", 48 | "avatar_url": "https://avatars0.githubusercontent.com/u/5046159?v=4", 49 | "profile": "http://pierrearnissolle.com", 50 | "contributions": [ 51 | "code" 52 | ] 53 | }, 54 | { 55 | "login": "HayriCan", 56 | "name": "Hayri Can BARÇIN", 57 | "avatar_url": "https://avatars2.githubusercontent.com/u/17090831?v=4", 58 | "profile": "https://www.linkedin.com/in/hayricanbarcin/", 59 | "contributions": [ 60 | "doc" 61 | ] 62 | } 63 | ], 64 | "contributorsPerLine": 7, 65 | "projectName": "Laravel-Overflow", 66 | "projectOwner": "CraftLogan", 67 | "repoType": "github", 68 | "repoHost": "https://github.com", 69 | "skipCi": true 70 | } 71 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer). 44 | 45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 46 | 47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 48 | 49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. 50 | 51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 52 | 53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 54 | 55 | **Happy coding**! 56 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Laravel Overflow Logo](https://raw.githubusercontent.com/CraftLogan/Laravel-Overflow/master/Laravel%20Overflow.png#logo) 2 | 3 | [![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors-) 4 | 5 | 6 | 7 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/craftlogan/laravel-overflow.svg?style=flat-square)](https://packagist.org/packages/craftlogan/laravel-overflow) 8 | ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/spatie/laravel-responsecache/run-tests?label=tests) 9 | [![MIT Licensed](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) 10 | [![Quality Score](https://img.shields.io/scrutinizer/g/craftlogan/laravel-overflow.svg?style=flat-square)](https://scrutinizer-ci.com/g/craftlogan/laravel-overflow) 11 | [![Total Downloads](https://img.shields.io/packagist/dt/craftlogan/laravel-overflow.svg?style=flat-square)](https://packagist.org/packages/craftlogan/laravel-overflow) 12 | 13 | # Laravel Overflow 14 | 15 | The Laravel Overflow package will allow adding an overflow column to a form request easily. Use this package to make it easy to store overflow request values in a JSON or Text column on a database table:) 16 | ## Installation 17 | 18 | You can install the package via composer: 19 | 20 | ```bash 21 | composer require craftlogan/laravel-overflow 22 | ``` 23 | 24 | ## Usage 25 | 26 | #### Create Model 27 | 28 | You should create a model which will use the overflow method. 29 | ```bash 30 | php artisan make:model TestModel -m 31 | ``` 32 | -m option generates database migration with the model. 33 | 34 | ``` php 35 | increments('id'); 58 | $table->string('name'); 59 | //$table->text('properties'); // Use this column type if you are using sqlite or a mysql version less than 5.7 60 | //$table->json('properties'); // If your database supports json then I would recommend using the json column 61 | $table->timestamps(); 62 | }); 63 | } 64 | 65 | ``` 66 | After setting up fields you should migrate your table. 67 | ```bash 68 | php artisan migrate 69 | ``` 70 | 71 | #### Available Macros 72 | There are `allWithOverflow` and `overflow` macros.You can payload Model and Overflow Field for each macros. 73 | 74 | #### `allWithOverflow` 75 | This macro returns all fields of model as an array 76 | ``` php 77 | $request->allWithOverflow(Model_Name,Overflow_Field) 78 | 79 | //Returns 80 | 81 | [ 82 | "properties" => "{"key1":"key1_value","key2":"key2_value"}", 83 | "name" => "overflow" 84 | ] 85 | ``` 86 | 87 | #### `overflow` 88 | This macro returns only Overflow Field as a json object 89 | ``` php 90 | $request->overflow(Model_Name,Overflow_Field) 91 | 92 | //Returns 93 | 94 | "{"key1":"key1_value","key2":"key2_value"}" 95 | ``` 96 | 97 | #### Insert record via ``create`` method 98 | 99 | You can use `Illuminate\Http\Request` for retrieving Http Requests. 100 | 101 | ``` php 102 | public function store(Request $request) 103 | { 104 | $testmodel = TestModel::create($request->allWithOverflow(new TestModel(),'properties')); 105 | } 106 | ``` 107 | Also, you can use your custom `Form Request`. 108 | 109 | ``` php 110 | public function store(\App\Http\Requests\TestFormRequest $request) 111 | { 112 | $testmodel = TestModel::create($request->allWithOverflow(new TestModel(),'properties')); 113 | } 114 | ``` 115 | #### Insert record via ``save`` method 116 | 117 | Using with the object Attributes: 118 | 119 | ``` php 120 | public function store(Request $request) 121 | { 122 | $testmodel = new TestModel(); 123 | $testmodel->name = $request->name; 124 | $testmodel->properties = $request->overflow(new TestModel(),'properties'); 125 | $testmodel->save(); 126 | } 127 | ``` 128 | 129 | ### Testing 130 | 131 | ``` bash 132 | composer test 133 | ``` 134 | 135 | ### Changelog 136 | 137 | Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. 138 | 139 | 140 | ## Contributors ✨ 141 | 142 | Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 |

Logan H. Craft

💻 📖

Daniel

💻

Laravel News

📝

Paul Redmond

📝

Pierre Arnissolle

💻

Hayri Can BARÇIN

📖
157 | 158 | 159 | 160 | 161 | 162 | 163 | ## Contributing 164 | 165 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 166 | 167 | This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! 168 | 169 | ## License 170 | 171 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 172 | 173 | 174 | This package used scafolding from the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com) built by [Marcel Pociot](https://twitter.com/marcelpociot) 175 | --------------------------------------------------------------------------------