How to use mysql zerofill in Laravel Migrations?

Asked

Viewed 206 times

1

I’m trying to add the zerofill of MySQL in the Migrations of Laravel but I’m not succeeding. Can you tell me how to do this ?

Follow my sample code by editing a table by adding this tinyint field with zerofill:

Schema::table('tabela1', function (Blueprint $table) {
    $table->tinyInteger('campo1')->zerofill()->unsigned()->nullable();
});

1 answer

2


There is no method for this in Migrations of Laravel, but you can use the class **DB**, for example:

Schema::table('tabela1', function (Blueprint $table) {
    $table->tinyInteger('campo1')->zerofill()->unsigned()->nullable();
});
DB::statement('ALTER TABLE tabela1 CHANGE campo1 campo1 INT UNSIGNED ZEROFILL');

OBS: Just remember to add the use DB in calls

Reference

Browser other questions tagged

You are not signed in. Login or sign up in order to post.