Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/CraftLogan/Laravel-Overflow

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:)
https://github.com/CraftLogan/Laravel-Overflow

Last synced: about 2 months ago
JSON representation

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:)

Awesome Lists containing this project

README

        

![Laravel Overflow Logo](https://raw.githubusercontent.com/CraftLogan/Laravel-Overflow/master/Laravel%20Overflow.png#logo)

[![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors-)

[![Latest Version on Packagist](https://img.shields.io/packagist/v/craftlogan/laravel-overflow.svg?style=flat-square)](https://packagist.org/packages/craftlogan/laravel-overflow)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/spatie/laravel-responsecache/run-tests?label=tests)
[![MIT Licensed](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Quality Score](https://img.shields.io/scrutinizer/g/craftlogan/laravel-overflow.svg?style=flat-square)](https://scrutinizer-ci.com/g/craftlogan/laravel-overflow)
[![Total Downloads](https://img.shields.io/packagist/dt/craftlogan/laravel-overflow.svg?style=flat-square)](https://packagist.org/packages/craftlogan/laravel-overflow)

# Laravel Overflow

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:)
## Installation

You can install the package via composer:

```bash
composer require craftlogan/laravel-overflow
```

## Usage

#### Create Model

You should create a model which will use the overflow method.
```bash
php artisan make:model TestModel -m
```
-m option generates database migration with the model.

``` php
increments('id');
$table->string('name');
//$table->text('properties'); // Use this column type if you are using sqlite or a mysql version less than 5.7
//$table->json('properties'); // If your database supports json then I would recommend using the json column
$table->timestamps();
});
}

```
After setting up fields you should migrate your table.
```bash
php artisan migrate
```

#### Available Macros
There are `allWithOverflow` and `overflow` macros.You can payload Model and Overflow Field for each macros.

#### `allWithOverflow`
This macro returns all fields of model as an array
``` php
$request->allWithOverflow(Model_Name,Overflow_Field)

//Returns

[
"properties" => "{"key1":"key1_value","key2":"key2_value"}",
"name" => "overflow"
]
```

#### `overflow`
This macro returns only Overflow Field as a json object
``` php
$request->overflow(Model_Name,Overflow_Field)

//Returns

"{"key1":"key1_value","key2":"key2_value"}"
```

#### Insert record via ``create`` method

You can use `Illuminate\Http\Request` for retrieving Http Requests.

``` php
public function store(Request $request)
{
$testmodel = TestModel::create($request->allWithOverflow(new TestModel(),'properties'));
}
```
Also, you can use your custom `Form Request`.

``` php
public function store(\App\Http\Requests\TestFormRequest $request)
{
$testmodel = TestModel::create($request->allWithOverflow(new TestModel(),'properties'));
}
```
#### Insert record via ``save`` method

Using with the object Attributes:

``` php
public function store(Request $request)
{
$testmodel = new TestModel();
$testmodel->name = $request->name;
$testmodel->properties = $request->overflow(new TestModel(),'properties');
$testmodel->save();
}
```

### Testing

``` bash
composer test
```

### Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):



Logan H. Craft

πŸ’» πŸ“–

Daniel

πŸ’»

Laravel News

πŸ“

Paul Redmond

πŸ“

Pierre Arnissolle

πŸ’»

Hayri Can BARÇIN

πŸ“–

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

This package used scafolding from the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com) built by [Marcel Pociot](https://twitter.com/marcelpociot)