Closed terranc closed 6 years ago
@terranc can you please provide us a real-world scenario where you would use virtual fields?
the migration code before:
public function up()
{
Schema::create('awards', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('name', 100)->nullable()->default(null);
$table->decimal('price', 10, 2)->default('0');
$table->decimal('service_fee', 10, 2)->default('0');
$table->decimal('sale_price', 10, 2)->virtualAs('`price` + `service_fee`');
$table->softDeletes();
$table->timestamps();
});
}
@terranc Thank you! Makes sense.
You could do this using a simple Eloquent accessor/getter. This seems to be a read-only field.
At the moment, we will not support this feature for the following reasons
Not like accessor/getter. Virtual fields make it easier to query in databases and use indexes.
Those are available since MySQL 5.7.