How to create laravel float data type migration

May 8, 2023
Laravel
How to create laravel float data type migration

In this guide, you will learn how to create the laravel float data type in the migration.

Laraval migration used float() to create a float type column in the database.

Laravel float data type migration

As we have discussed that we will using Laravel migration method float() to create float type column in the database.

The float() method accepts 3 arguments:

1- Column Name

2- Total digits

3- Digits after decimal

So for example float(‘amount’, 6, 2), here we can save total 6 digits, from which 2 are after decimal

Also Read: Add New Column to Existing Table in a Migration

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddNewColumnToUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
       Schema::table('users', function (Blueprint $table) {
           $table->float('amount', 6, 2);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
}

Conclusion

Hope in the above article, you have learn how to add and create laravel float data type migration

Write a Reply or Comment

Your email address will not be published. Required fields are marked *


Icon