database Symfony\Component\Debug\Exception\FatalErrorException 未找到类“注释”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33482475/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Symfony\Component\Debug\Exception\FatalErrorException Class 'Comments' not found
提问by Eieur Geir Vilhelmsson
My model Comments.php: I'm not including the class anywhere I just created the model and the migration and nothing works, I am so confused I can't think straight.
我的模型 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');
}
}
And here is my migration:
这是我的迁移:
<?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');
}
}
Now once I run the command "php artisan migrate:rollback and /or refresh" I get this error code:
现在,一旦我运行命令“php artisan migrate:rollback and/or refresh”,我就会收到此错误代码:
"[Symfony\Component\Debug\Exception\FatalErrorException] Class 'Comments' not found"
“ [Symfony\Component\Debug\Exception\FatalErrorException] 未找到类“注释””
Only way for me to refresh the tables is to manually drop all tables with phpMyAdmin and run "php artisan migrate"
我刷新表的唯一方法是使用 phpMyAdmin 手动删除所有表并运行“php artisan migrate”
But I don't know if that is healthy.
但我不知道这是否健康。
回答by Болоршагай Э.
composer dump-autoload
composer update
- Migration file name is in the right format (
YYYY_MM_DD_HHMMSS_filename.php
)
composer dump-autoload
composer update
- 迁移文件名格式正确 (
YYYY_MM_DD_HHMMSS_filename.php
)
回答by Shohanul Alam
May be your model name will be "Comment" not "Comments". Because laravel uses the plural form of the name fo model as the default database. Such as User model for users table, Comment model for comments table.
可能您的模型名称将是“评论”而不是“评论”。因为 laravel 使用名称 fo 模型的复数形式作为默认数据库。例如用户表的用户模型,评论表的评论模型。
回答by Smit Patel
Try including use App/Comments
in your controller file. I hope it will work, and if it dont work then check for any spelling mistake and also double check your ROUTES.
尝试包含use App/Comments
在您的控制器文件中。我希望它会起作用,如果它不起作用,请检查任何拼写错误并仔细检查您的ROUTES。