16

GitHub - CraftLogan/Laravel-Overflow: The Laravel Overflow package will allow ad...

 4 years ago
source link: https://github.com/CraftLogan/Laravel-Overflow
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md

Laravel Overflow Logo

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

Defining the overflow column and table using a custom form request:

<?php

namespace CraftLogan\LaravelOverflow\Requests;

use Illuminate\Foundation\Http\FormRequest;
use CraftLogan\LaravelOverflow\Overflowable;

class OverflowFormRequest extends FormRequest
{
    use Overflowable;
    public $table = 'test_models';
    public $overflow_column = 'properties';


    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [];
    }
}

Using with the CREATE Method:

public function store(CustomFormRequest $request)
{
    $testmodel = TestModel::create($request->allWithOverflow());
}

Using with the object Attributes:

        $testmodel = new TestModel();
        $testmodel->name = $request->name;
        $testmodel->properties = $request->overflow();
        $testmodel->save();

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->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();
        });
    }

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

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 Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK