admin管理员组文章数量:1395185
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!
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!
Share Improve this question asked Mar 14 at 4:56 Filbert UmbawaFilbert Umbawa 114 bronze badges 11- 1 Money has been deprecated since probably the fall of soviet union, why would you want to use it in new code? – siggemannen Commented Mar 14 at 7:21
- What do you mean? I asking about migration with money datatype in Laravel for SQL Server. – Filbert Umbawa Commented Mar 14 at 7:29
- i mean, dont't use money datatype. Use numeric – siggemannen 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? – Filbert Umbawa Commented Mar 14 at 8:53
- 2 blog.greglow/2018/01/15/… – jarlh Commented Mar 14 at 9:14
1 Answer
Reset to default -1Laravel 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
本文标签: phpHow to Define a money Data Type in Laravel Migrations for SQL ServerStack Overflow
版权声明:本文标题:php - How to Define a money Data Type in Laravel Migrations for SQL Server? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744673313a2618959.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论