【问题标题】:Laravel 5 - Class 'comment' not foundLaravel 5 - 找不到类“评论”
【发布时间】:2016-07-06 04:24:09
【问题描述】:
  1. 我使用php artisan make:model Comment 命令创建了一个新模型
  2. 我使用以下代码创建了一个名为 CommentTableSeeder 的新数据库播种器:

    <?php
    

使用 Illuminate\Database\Seeder;

类 CommentTableSeeder 扩展 Seeder

{

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('comments')->delete();

    Comment::create(array(
    'author' => 'A name',
    'text' => 'Hello all nice website'
    ));

    Comment::create(array(
    'author' => 'name2',
    'text' => 'Hahahahha'
    ));

    Comment::create(array(
    'author' => 'Name 3,
    'text' => 'I destroy your car'
    ));
}

}

  1. 我运行了php artisan db:seed 命令,但出现错误: Class 'Comment' not found

为什么?

【问题讨论】:

  • 您之前是否运行过迁移?
  • 如果你的意思是数据库迁移,是的
  • 请分享您的完整播种代码?

标签: php laravel


【解决方案1】:

添加这些行:

use App\Comment;

另外,你可以使用这个:

\App\Comment::

代替

Comment::

【讨论】:

  • 效果很好!谢谢!我不知道我需要提及具体型号。
  • @TheUnreal,很高兴它有帮助。 )
猜你喜欢
  • 1970-01-01
  • 2020-01-31
  • 2015-07-17
  • 1970-01-01
  • 1970-01-01
  • 2020-02-01
  • 2015-10-20
  • 2016-11-26
  • 1970-01-01
相关资源
最近更新 更多