CraftLogan/
Laravel-Overflow
g4t.io

Store Extra Columns as JSON With Laravel Overflow

17 views 109 stars by Paul Redmond

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

README from CraftLogan/Laravel-Overflow Open on GitHub →

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

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

More from the ecosystem

durable-workflow/
workflow
g4t.io
9 1,292

Durable Workflow: Long-Running Workflows for Laravel

Embedded durable workflow runtime and orchestration engine for Laravel applications.

durable-workflow/workflow via Laravel News
packstub/
session-replay
g4t.io
14 52

Session Replay for Laravel: Self-Hosted Browser Recordings

Session replay for Laravel: record what a person did in the browser with rrweb, keep the recording on your own disk and database, and watch it behind a gate you define — masked inputs by default, errors, failed Livewire requests and web vitals marked on the timeline, a link to the replay in every log line. packstub/filament-session-replay adds the sessions to a Filament panel.

packstub/session-replay via Laravel News
cyberwizard-dev/
schedule-catchup
g4t.io
17

Replay Missed Laravel Scheduled Tasks With Schedule Catchup

Schedule Catchup replays missed Laravel scheduled tasks after downtime, with opt-in recovery, bounded retries, and access to the original scheduled date.

cyberwizard-dev/schedule-catchup via Laravel News