1
我是Laravel和PHP的新手,所以我面對和錯誤我不知道如何解決。Laravel遷移繼承不起作用
基本的問題是,因爲很多表有primary:id
和created_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()
?
我缺少什麼?感謝您的善意幫助。