外键在laravel 5.4中显示语法错误

时间:2017-05-10 05:35:39

标签: php laravel migration laravel-5.3

我已经创建了迁移文件,我写了:

public function up()
    {
        //
        Schema::create('ad_group', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('campaign_id')->unsigned();
            $table->char('name',32);
        });
        Schema::table('ad_group',function (Blueprint $table){
            $table->foreign('campaign_id')->references->('id')->on('campaigns');
        });
    }

返回如下错误:

[Symfony的\元器件\调试\异常\ FatalThrowableError]
  解析错误:语法错误,意外'(',期望标识符(T_STRING)或变量(T_VARIABLE)或'{'或'$'

1 个答案:

答案 0 :(得分:0)

Your mistake is  "->references->('id')->" must be "->references('id')->"

public function up() {
    Schema::table('ad_group', function (Blueprint $table) {
          $table->foreign('campaign_id')->references('id')->on('campaigns');
    });
}

希望有所帮助:)