0

I'm working with Laravel migrations and need to define a money column type in SQL Server. However, Laravel's schema builder does not provide a direct money type.

I’ve considered two approaches:

Using raw SQL:

Schema::table('your_table', function (Blueprint $table) {
    DB::statement("ALTER TABLE your_table ADD price MONEY");
});

Using decimal as an alternative:

Schema::table('your_table', function (Blueprint $table) {
    $table->decimal('price', 19, 4);
});

I prefer a solution that works natively with Laravel’s schema builder. Is there a way to register a custom column type for money, or is raw SQL the only option?

Any recommendations for best practices in Laravel with SQL Server are appreciated!

11
  • 1
    Money has been deprecated since probably the fall of soviet union, why would you want to use it in new code? Commented Mar 14 at 7:21
  • What do you mean? I asking about migration with money datatype in Laravel for SQL Server. Commented Mar 14 at 7:29
  • i mean, dont't use money datatype. Use numeric Commented Mar 14 at 7:51
  • The problem when wanna counting of that records (the datatype field is double in SQL Server). When count the value that double datatype in Laravel. It comes not same value. SQL Server Record A Value = 0.2 (Double datatype) When get in Laravel Query Builder of A Value = 0.19999999 (Float in migration) So that, i wanna change my datatype from double to money Maybe that has other configuration in Laravel to handle my case? Commented Mar 14 at 8:53
  • 2
    blog.greglow.com/2018/01/15/…
    – jarlh
    Commented Mar 14 at 9:14

1 Answer 1

-1

Laravel does not provide a direct money column type.
I think using decimal is the better option, but if u really need the money type then use raw SQL

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.