2016-10-16 11 views
1

私はLaravelとphpの新機能ですので、私は直面してエラーを解決する方法がわかりません。Laravelの移行継承が機能していません

基本的な問題は、多くのテーブルにはprimary:idcreated_by,updated_byのカラムがあり、私の移行でそれらを継承しているからです。

私はPHP7

を使用していますがだから私は、基本クラスに

class BaseMigration extends Migration { 

    public function up(string $tableName) { 
    Schema::create($tableName, function (Blueprint $table) { 
     $table->mediumIncrements('id'); 
     $table->primary('id'); 

     $table->unsignedMediumInteger('created_by')->references('id')->on('users'); 
     $table->unsignedMediumInteger('updated_by')->references('id')->on('users'); 
    }); 
    } 
} 

と拡張移行

class CreateItemsTable extends BaseMigration { 

    public function up() { 
     parent::up('items'); 

     Schema::create('items', function (Blueprint $table) { 

      $table->string('name', 74); 
      $table->timestamps(); 
     }); 
    } 

    // ...... 
} 

を持っているしかしphp artisan migrateは私にこれを与える:

[ErrorException] Declaration of CreateItemsTable::up() should be compatible with Illuminate\Database\Migrations\BaseMigration::up(string $tableName)

私はダブルを実行しているためですかup()

私には何が欠けていますか?あなたの親切な助けを感謝します。

答えて

2

私はあなたが同じ関数シグネチャを持っているので、string $tableNameに合格する必要があると思う:

class CreateItemsTable extends BaseMigration { 

    public function up(string $tableName) { 
     Schema::create('items', function (Blueprint $table) { 
      parent::up('items'); 

      $table->string('name', 74); 
      $table->timestamps(); 
     }); 
    } 

    // ...... 
} 
関連する問題