我的模型 Comments.php: 我没有在我刚刚创建模型和迁移的任何地方包括该类,但没有任何效果,我很困惑,无法理清思路。
<?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 artisan migrate:rollback and/or refresh”,我就会得到这个错误代码:
"[Symfony\Component\Debug\Exception\FatalErrorException] Class 'Comments' not found"
我刷新表格的唯一方法是使用 phpMyAdmin 手动删除所有表格并运行“php artisan migrate”
但我不知道那是否健康。
最佳答案
Composer 转储自动加载
Composer 更新
- 迁移文件名的格式正确(
YYYY_MM_DD_HHMMSS_filename.php
)
关于database - 找不到 Symfony\Component\Debug\Exception\FatalErrorException 类 'Comments',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33482475/