stancl / virtualcolumn
Eloquent virtual column.
Installs: 3 318 860
Dependents: 9
Suggesters: 0
Security: 0
Stars: 72
Watchers: 4
Forks: 12
Open Issues: 1
Requires
- illuminate/database: ^9.0|^10.0|^11.0
- illuminate/support: ^9.0|^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^7.0|^8.0|^9.0
This package is auto-updated.
Last update: 2024-12-07 19:55:47 UTC
README
Installation
Supports Laravel 9, 10, 11.
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']);