I am using Laravel 5.3, I want to define a field in table migration as nullable as well as unsigned. As both are index modifier, can I use them in concatenation ? Like:
$table->integer('some_field')->unsigned()->nullable();
Please also give some reference if there is to these kind of modifications in laravel documentation or somewhere.
Please note that I want to define field in up()
function as unsigned as well as nullable. I dont want solutions with down()
function like:
public function up()
{
Schema::create('ex', function (Blueprint $table) {
$table->integer('some_field')->unsigned();
});
}
public function down()
{
DB::statement('ALTER TABLE ex MODIFY `some_field` integer NOT NULL;');
}
Thanks in advance!
You can do
Schema::create('ex', function (Blueprint $table) {
$table->integer('some_field')->unsigned()->nullable();
});
You can. Laravel allows a lot of method-chaining. Each of the column methods is defined to return the same Blueprint
object, so you can easily call another method on it. This means you could even do:
Schema::create('ex', function (Blueprint $table) {
$table->integer('some_field')->unsigned()->default(10);
});
And all would be well :)
For further information, see the documentation on database migrations (see the section on "Column Modifiers").
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With