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

creating a column for price in a laravel schema

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

I want to create a column for price in a laravel schema.

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

Or is there an alternative data type I can use? As I don't see anything for monetary value in the documentation. Any help would be appreciated.

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

There is 'float' type for your purpose it seems fine unless you don't want to save currency too:

$table->float('amount')

Available types are listed in documentation. https://laravel.com/docs/5.4/migrations#creating-columns

If you do want to save currency with price you will have to use string , or create a new column for currency-type can be another work around.