1
0
Fork 0
mirror of https://github.com/archtechx/virtualcolumn.git synced 2025-12-12 05:14:05 +00:00
Eloquent Virtual Column package.
Find a file
2020-07-06 14:25:29 +02:00
.github/workflows Initial commit 2020-07-06 14:25:02 +02:00
src Initial commit 2020-07-06 14:25:02 +02:00
tests Initial commit 2020-07-06 14:25:02 +02:00
.gitattributes Initial commit 2020-07-06 14:25:02 +02:00
.gitignore Initial commit 2020-07-06 14:25:02 +02:00
composer.json Initial commit 2020-07-06 14:25:02 +02:00
composer.lock Initial commit 2020-07-06 14:25:02 +02:00
LICENSE Initial commit 2020-07-06 14:25:02 +02:00
phpunit.xml Initial commit 2020-07-06 14:25:02 +02:00
README.md model -> trait 2020-07-06 14:25:29 +02:00

Eloquent Virtual Column

Installation

Supports Laravel 6 and 7.

composer require stancl/virtual-column

Usage

Use the VirtualColumn trait on your model:

use Illuminate\Database\Eloquent\Model;
use Stancl\VirtualColumn\VirtualColumn;

class MyModel extends Model
{
    use VirtualColumn;

    public $guarded = [];
}

Create a migration:

public function up()
{
    Schema::create('my_models', function (Blueprint $table) {
        $table->increments('id');

        $table->string('custom1')->nullable();
        $table->string('custom2')->nullable();

        $table->json('data');
    });
}

And store any data on your model:

$myModel = MyModel::create(['foo' => 'bar']);
$myModel->update(['foo' => 'baz']);