stancl/virtualcolumn
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...
641,106,524
9,700
laravel/serializable-closure
Laravel Serializable Closure provides an easy and secure way to serialize closur...
418,291,778
609
nunomaduro/collision
Cli error handling for console/command-line PHP applications.
394,964,158
4,660
Version History
| Version | Released | Laravel | License |
|---|---|---|---|
| v1.5.0 | >=10.0 | MIT | |
| v1.4.1 | ^9.0| | MIT | |
| v1.4.0 | ^9.0| | MIT | |
| v1.3.1 | ^9.0| | MIT | |
| v1.3.0 | ^6.0| | MIT | |
| v1.2.1 | ^6.0| | MIT | |
| v1.2.0 | ^6.0| | MIT | |
| v1.1.0 | ^6.0| | MIT | |
| v1.0.0 | ^6.0| | MIT |