使用laravel在字段模式迁移中定义属性zerofill和大小

Jér*_*lle 1 php laravel

如何在使用Laravel进行字段模式迁移时定义属性zerofill和size(2)?

Schema::create('books', function (Blueprint $table) {
    $table->integer('reference')->length(2);
});
Run Code Online (Sandbox Code Playgroud)

和这个字段为zerofill。

我想使用播种机:

public function run()
{
    Book::create
    ([
        'reference' => 01
    ]);
}
Run Code Online (Sandbox Code Playgroud)

Fie*_*ete 6

Zerofill不是SQL标准。laravel的shema构建器仅提供这些ANSI SQL标准。

但是您可以使用变通方法通过原始sql语句进行定义:

create_books.php

Schema::create('books', function (Blueprint $table) {
    $table->integer('reference');
});
DB::statement('ALTER TABLE books CHANGE reference reference INT(2) UNSIGNED ZEROFILL NOT NULL');
Run Code Online (Sandbox Code Playgroud)