【发布时间】:2018-03-14 04:04:58
【问题描述】:
当我运行 php artisan migrate 时,我收到如下错误:
In 2017_12_26_045926_create_table_articles.php line 41:
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting ',' or
')'
这是我的文章表格:
public function up()
{
Schema::create('articles', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->integer('category_id');
$table->string('title');
$table->text('content');
$table->boolean('is_show')->default(false);
$table->boolean('is_active')->default(false);
$table->integer('page_showing')->default(0);
$table->string('header_pic');
$table->softDeletes();
$table->timestamps();
Schema::table('articles', function($table){
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('articles');
}
}
我正在为文章和 cmets 添加外键,但迁移时的文章表会出现上述错误。怎么了?
【问题讨论】:
-
这不是有效的 PHP。它甚至会告诉你哪一行是无效的(我们其他人看不到)。