How to create laravel float data type migration

Here we explain how to make float dataType migration in laravel.


Laravel float data type migration

Laravel migration float() method create float type sql column in table. In float method we pass three arguments first name second total digits and third total digits after decimal.

Let an example float('amount', 8, 2) here we can save max 6 digit number and 2 points after decimal.

<?php
  
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->float('amount', 8, 2);
        });
    }
  
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('orders');
    }
};
php laravel developer anmol sharma

Anmol Sharma

I am a software engineer and have experience in web development technologies like php, Laravel, Codeigniter, javascript, jquery, bootstrap and I like to share my deep knowledge by these blogs.

Random tutorial links