2016-10-16 3 views
1

저는 Laravel과 PHP를 처음 접해서 얼굴을 보았고 오류를 해결할 방법을 모르겠습니다.Laravel 마이그레이션 상속이 작동하지 않습니다.

기본 문제는 많은 테이블이 primary:idcreated_by,updated_by 열을 가지고 있기 때문에 기본 마이그레이션에서 마이그레이션을 상속하는 것입니다.

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

: 나는 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 날이 제공하는 확장 마이그레이션을 가지고

두번 실행 중이기 때문에 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(); 
     }); 
    } 

    // ...... 
} 
관련 문제