php - Define property zerofill and size on field schema migration with laravel
976
How can I define property zerofill and size (2) on field schema migration with Laravel?
Schema::create('books', function (Blueprint $table) {
$table->integer('reference')->length(2);
});
and this field with zerofill.
I would like use my seeder:
public function run()
{
Book::create
([
'reference' => 01
]);
}
Answer
Solution:
Zerofill is not a SQL standard. The shema builder of laravel provides only these ANSI SQL standards.
But you can use a workaround to define it with a raw sql statement:
create_books.php
Answer
Solution:
As mentioned, in order to keep your migrations portable, you'll want to use an accessor to provide that. It'll look something like this:
Book.php model