PHP code example of zanysoft / virtualcolumn

1. Go to this page and download the library: Download zanysoft/virtualcolumn library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zanysoft / virtualcolumn example snippets


use Illuminate\Database\Eloquent\Model;
use ZanySoft\VirtualColumn\VirtualColumn;

class MyModel extends Model
{
    use VirtualColumn;

    public $guarded = [];
}

use Illuminate\Database\Eloquent\Model;
use ZanySoft\VirtualColumn\VirtualColumn;

class MyModel extends Model
{
    use VirtualColumn;

    public static function getDataColumn(): string
    {
        return 'data'; //name of the column that stores additional data.
    }
}

use Illuminate\Database\Eloquent\Model;
use ZanySoft\VirtualColumn\VirtualColumn;

class MyModel extends Model
{
    use VirtualColumn;

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

public function up()
{
    Schema::create('my_models', function (Blueprint $table) {
        $table->increments('id');

        $table->string('custom1')->nullable();
        $table->string('custom2')->nullable();

        $table->json('data');
    });
}

$myModel = MyModel::create(['custom1' => 'custom 1', 'custom2' => 'custom 2', 'foo' => 'bar']);
$myModel->update(['custom1' => 'custom 1', 'custom2' => 'custom 2', 'foo' => 'bar']);