fisharebest/laravel-floats
最新稳定版本:1.5.0
Composer 安装命令:
composer require fisharebest/laravel-floats
包简介
Floating point support for Laravel migrations
README 文档
README
laravel-floats
This package allows database migrations in Laravel 5, Laravel 6 and Laravel 7 to create FLOAT columns in MySQL.
Huh? You mean that Laravel does not support floating point columns?
Sadly no. It only supports double-precision floating point columns.
If you want single-precision floating point, you need to use DB::raw().
This is despite the Laravel documentation at https://laravel.com/docs/5.8/migrations which states:
$table->float('amount', 8, 2);FLOAT equivalent column with a precision (total digits) and scale (decimal digits).
$table->double('amount', 8, 2);DOUBLE equivalent column with a precision (total digits) and scale (decimal digits).
You can read all about it at laravel/framework#3151 and many other issues.
| In your migration | Laravel 5.0 - 7.0 | With this package |
|---|---|---|
$table->float('col'); |
DOUBLE(8,2) |
FLOAT |
$table->float('col', 0); |
DOUBLE |
FLOAT |
$table->float('col', 5); |
DOUBLE(5,2) |
FLOAT |
$table->float('col', 5, 3); |
DOUBLE(5,3) |
FLOAT(5,3) |
$table->double('col'); |
DOUBLE |
DOUBLE |
$table->double('col', 0); |
DOUBLE |
DOUBLE |
$table->double('col', 5); |
DOUBLE |
DOUBLE |
$table->double('col', 5, 3); |
DOUBLE(5,3) |
DOUBLE(5,3) |
Installation
composer require fisharebest/laravel-floats
Package discovery takes care of everything on Laravel 5.5 and later.
If you're using Laravel 5.4 or earlier, you'll need to replace an alias in config/app.php.
'aliases' => [
...
'Schema' => \Fisharebest\LaravelFloats\Schema::class,
....
]
NOTE: this assumes you are using Laravel to autoload your facades using the aliases.
If you explicitly import Laravel's schema builder using use Illuminate\Support\Facades\Schema; then you will need to change this to use Fisharebest\LaravelFloats\Schema;.
How does this package work?
We extend the MySQL Grammar, modify the blueprint for float(), and then
bind the updated grammar back into the IoC container.
统计信息
- 总下载量: 11.34k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-18