我的模型评论.php: 我没有在任何地方包括类我刚创建模型和迁移,没有任何作品,我很困惑我不能直视。Symfony Component Debug Exception FatalErrorException类'评论'未找到
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
class Comments extends Model {
protected $fillable = [
'id',
'user_id',
'post_id',
'comment'
];
public function setPublishedAtAttribute($date)
{
$this->attributes['pubslished_at'] = Carbon::parse($date);
}
public function user()
{
return $this->belongsTo('App\User');
}
public function posts()
{
return $this->belongsTo('App\Posts');
}
}
这里是我的移民:
<?php
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')->unsigned();
$table->integer('post_id')->unsigned();
$table->text('comment');
$table->timestamps();
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade');
$table->foreign('post_id')
->references('id')
->on('posts')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('comments');
}
}
现在,当我运行命令 “PHP工匠迁移:回滚和/或刷新” 我得到这个错误代码:
“ [Symfony \ Component \ Debug \ Exception \ FatalErrorException] Class'Comments'Not found“
刷新表格的唯一方法是用phpMyAdmin手动删除所有表格并运行“php artisan migrate”
但我不知道这是否健康。
你能测试一个路径迁移后的作品?另外,启用调试并检查日志中的错误描述。 –
尝试先做一个作曲家dump-autoload -o然后php artisan migrate:回滚和/或刷新。此外,Laravel希望你的模型能够以单数“评论”和你的表格复数形式“评论”,如果你想保留你的模型为“评论”添加保护$ table =“comments” –
我不知道为什么,但“作曲家转储-autoload -o“命令修复了我的问题,请仔细说明它是如何工作的?这是一个全新的命令:) 也谢谢;) –