更新时间:2022-12-12 11:08:16
您可以在迁移中定义它:
You can define this in your migration:
$table->integer('area')->virtualAs('height * width');
每次读取都会生成,或者
to be generated on every read, or
$table->integer('area')->storedAs('height * width');
如果您不希望生成始终保持不变,则希望将列存储在数据库中.
if you want to store the column in the database if you don't want the generation to be always.
,然后将area
列添加到模型中.这样,您既可以在查询中也可以在模型中使用该字段.
and then add the area
column to your model. This way you can use the field in both queries and models.