Warm tip: This article is reproduced from serverfault.com, please click

php-在laravel模式中为价格创建一个列

(php - creating a column for price in a laravel schema)

发布于 2017-07-08 10:11:05

我想在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();
    });
}

还是我可以使用另一种数据类型?因为我在文档中没有看到任何有关货币价值的信息。任何帮助,将不胜感激。

Questioner
AltBrian
Viewed
0
3,958 2021-02-09 16:05:08

出于你的目的,有一个“浮动”类型,除非你也不想节省货币,否则这似乎很好:

$table->float('amount')

可用类型在文档中列出。 https://laravel.com/docs/5.4/migrations#creating-columns

如果你确实想用价格来保存货币,则必须使用string,或者为currency-type创建一个新列也可以解决。