简体   繁体   English

laravel中的整数可空列

[英]Integer nullable column in laravel

Is it possible to have integer column nullabale in laravel? 是否可以在laravel中使用整数列nullabale?

I have table image where i store multiple image and get id of my posts products website_banner and I need them to be nullable. 我有表格image ,我存储多个图像,并获得我的posts products website_banner ,我需要它们可以为空。 For example if I upload multiple image for my product not get error of my posts column have not default value! 例如,如果我为我的产品上传多个图像而不是我的帖子列的错误没有默认值!

my migrations: 我的迁移:

Schema::create('images', function (Blueprint $table) {
            $table->increments('id');
            $table->string('image');
            $table->integer('post_id')->unsigned();
            $table->integer('product_id')->unsigned();
            $table->integer('banner_id')->unsigned();
            $table->timestamps();
        });

Schema::table('images', function($table) {
            $table->foreign('post_id')->references('id')->on('posts');
            $table->foreign('product_id')->references('id')->on('products');
            $table->foreign('banner_id')->references('id')->on('banners');
        });

$表 - >整数( 'banner_id') - >可为空的() - >无符号();

是的,只需将->nullable()到您的行:

$table->integer('website_banner')->unsigned()->nullable();

你必须使用可空的

$table->integer('column_name')->nullable()->unsigned();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM