New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

stancl/virtualcolumn

Eloquent virtual column.
12,043,717 85
Install
composer require stancl/virtualcolumn
Latest Version:v1.5.0
Laravel:10 · 11 · 12
Older releases:6 – 9
License:MIT
Last Updated:Mar 18, 2026
Links: GitHub  ·  Packagist
Maintainer: stancl

Eloquent Virtual Column

Installation

Supports Laravel 10, 11, 12, and 13.

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

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

651,963,193 9,701
laravel/framework

The Laravel Framework.

604,216,237 34,982
laravel/tinker

Powerful REPL for the Laravel framework.

518,004,183 7,444
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

435,097,283 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

407,699,310 4,663

Version History

Version Released Laravel License
v1.5.0 >=10.0 MIT
v1.4.1 ^9.0|^10.0|^11.0 MIT
v1.4.0 ^9.0|^10.0|^11.0 MIT
v1.3.1 ^9.0|^10.0 MIT
v1.3.0 ^6.0|^8.0|^9.0 MIT