Code Monkey home page Code Monkey logo

laravel-overflow's Introduction

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

laravel-overflow's People

Contributors

craftlogan avatar allcontributors[bot] avatar danielgilb avatar hayrican avatar arnissolle avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.