Skip to content
This repository has been archived by the owner on Jan 27, 2023. It is now read-only.

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

License

Notifications You must be signed in to change notification settings

CraftLogan/Laravel-Overflow

Repository files navigation

Laravel Overflow Logo

All Contributors

Latest Version on Packagist GitHub Workflow Status MIT Licensed Quality Score Total Downloads

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:

composer require craftlogan/laravel-overflow

Usage

Create Model

You should create a model which will use the overflow method.

php artisan make:model TestModel -m

-m option generates database migration with the model.

   <?php
   
   namespace App;
   
   use Illuminate\Database\Eloquent\Model;
   
   class TestModel extends Model
   {
     
       protected $guarded = [];   // you should use either $fillable or $guarded
   }

Edit Migration

When setting up a migration you can use a json column or a text column:

    public function up()
    {
        Schema::create('test_models', function (Blueprint $table){
            $table->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.

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

    $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

    $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.

public function store(Request $request)
{
    $testmodel = TestModel::create($request->allWithOverflow(new TestModel(),'properties'));
}

Also, you can use your custom Form Request.

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:

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

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Logan H. Craft

💻 📖

Daniel

💻

Laravel News

📝

Paul Redmond

📝

Pierre Arnissolle

💻

Hayri Can BARÇIN

📖

Contributing

Please see CONTRIBUTING for details.

This project follows the all-contributors specification. Contributions of any kind welcome!

License

The MIT License (MIT). Please see License File for more information.

This package used scafolding from the Laravel Package Boilerplate built by Marcel Pociot

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages