database - 找不到 Symfony\Component\Debug\Exception\FatalErrorException 类 'Comments'

标签 database laravel migration models

我的模型 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”

但我不知道那是否健康。

最佳答案

  1. Composer 转储自动加载
  2. Composer 更新
  3. 迁移文件名的格式正确(YYYY_MM_DD_HHMMSS_filename.php)

关于database - 找不到 Symfony\Component\Debug\Exception\FatalErrorException 类 'Comments',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33482475/

相关文章:

php - Laravel 如何为 where like 查询动态数组列名称?

php - 在 Laravel 5.x 配置文件中访问 PHP super 全局变量的最佳方法

c# - Entity Framework 虚拟集合初始化

PHP - mySQL - 表单无法工作

php - 尝试更新2个表中的数据

mysql - 如何在MySQL表中使用迁移查询来替换记录?

c# - Microsoft OracleClient迁移到ODP.NET时报错 "ORA-03135: Connection lost contact"是什么原因

sql - 如何从 Access 表中获取选择性记录

javascript - 需要使用 fetch 从(laravel api)获取数据,然后将其解析到另一个函数

laravel-5 - 时间戳更改字段上的迁移错误