首页 文章

Laravel 5 - 找不到类'comment'

提问于
浏览
1
  • 我用 php artisan make:model Comment 命令创建了一个新模型

  • 我使用以下代码创建了一个名为 CommentTableSeeder 的新数据库播种机:

<?php

使用Illuminate \ Database \ Seeder;

class 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'
    ));
}

}

  • 我运行了 php artisan db:seed 命令,我收到错误: Class 'Comment' not found

为什么?

1 回答

  • 2

    添加以下行:

    use App\Comment;
    

    此外,您可以使用此:

    \App\Comment::
    

    代替

    Comment::
    

相关问题