1
0
Fork 0
mirror of https://github.com/archtechx/virtualcolumn.git synced 2025-12-12 20:14:03 +00:00
Eloquent Virtual Column package.
Find a file
2023-08-09 12:16:57 +02:00
.github/workflows Add L10 support, remove L6 and L8 support (#11) 2023-02-16 11:34:42 +01:00
src Break code style (testing) 2023-08-09 12:16:57 +02:00
tests Correct expected/actual value order in assertions 2023-08-08 16:57:58 +02:00
.gitattributes Initial commit 2020-07-06 14:25:02 +02:00
.gitignore wip 2022-01-26 21:54:10 +05:00
.php-cs-fixer.php wip 2022-01-26 21:54:10 +05:00
check wip 2022-01-26 21:54:10 +05:00
composer.json Add L10 support, remove L6 and L8 support (#11) 2023-02-16 11:34:42 +01:00
LICENSE Initial commit 2020-07-06 14:25:02 +02:00
phpunit.xml Add APP_KEY to phpunit.xml 2023-08-08 09:41:10 +02:00
README.md Add L10 support, remove L6 and L8 support (#11) 2023-02-16 11:34:42 +01:00

Eloquent Virtual Column

Installation

Supports Laravel 9 and 10.

composer require stancl/virtualcolumn

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 = [];

    public static function getCustomColumns(): array
    {
        return [
            'id',
            'custom1',
            'custom2',
        ];
    }
}

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']);