Search code examples
phplaravel-5schema

Creating a Column for Price in Laravel Schema


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.


Solution

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

    $table-> decimal('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.