1
0
Fork 0
mirror of https://github.com/archtechx/virtualcolumn.git synced 2025-12-11 01:04:03 +00:00
Eloquent Virtual Column package.
Find a file
Samuel Štancl 4664d00099
Merge pull request #24 from archtechx/fix-tests
Include timestamps in `getCustomColumns()` by default, fix tests (use new #[Test] attribute)
2025-12-06 16:41:58 +01:00
.github/workflows update CI matrix 2025-02-25 13:09:31 +01:00
src Add timestamp columns to the default getCustomColumns() 2025-07-22 13:09:08 +02:00
tests Merge pull request #24 from archtechx/fix-tests 2025-12-06 16:41:58 +01: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 use >= version constraints 2025-02-14 14:30:47 +01:00
LICENSE Initial commit 2020-07-06 14:25:02 +02:00
phpunit.xml Add encrypted casts support + allow using the trait on multiple models (#14) 2023-11-08 10:08:34 +01:00
phpunit.xml.bak Add encrypted casts support + allow using the trait on multiple models (#14) 2023-11-08 10:08:34 +01:00
README.md update supported version in readme 2025-02-25 14:12:44 +01:00

Eloquent Virtual Column

Installation

Supports Laravel 10, 11, and 12.

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