我在laravel项目上工作,每次更改表(添加或删除列)并运行PHP artisan migrate:refresh时.我收到此错误:
[Symfony\Component\Debug\Exception\FatalErrorException] Can’t use
method return value in write context
解决方案尝试:
>运行composer dump-autoload(失败)
>在数据库中删除表,删除迁移文件,然后再次重新启动(有效)
先前的迁移文件:
<?PHP
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCommentsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('comments', function (Blueprint $table) {
$table->increments('id');
$table->integer('post_id');
$table->string('body');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('comments');
}
}
更改的迁移文件:
<?PHP
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCommentsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('comments', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->integer('post_id');
$table->string('body');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('comments');
}
}
解决方法:
试试这个命令对我有用
PHP artisan migrate:fresh