我想在Laravel模式中为价格创建一个列。
public function up()
{
Schema::create('cameras', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('condition');
$table->string('price');
$table->string('type');
$table->timestamps();
});
}
还是我可以使用另一种数据类型?因为我在文档中没有看到任何有关货币价值的信息。任何帮助,将不胜感激。
出于你的目的,有一个“浮动”类型,除非你也不想节省货币,否则这似乎很好:
$table->float('amount')
可用类型在文档中列出。 https://laravel.com/docs/5.4/migrations#creating-columns
如果你确实想用价格来保存货币,则必须使用string,或者为currency-type创建一个新列也可以解决。
浮动会导致精度问题。更好地使用
decimal
。小数是应使用的,请参阅这篇文章