我试图为我的数据库播种时出错

时间:2018-01-22 14:07:53

标签: php laravel laravel-5.4

当我尝试使用faker

在laravel 5.4中播种数据库时出现错误
use Illuminate\Database\Seeder;
use app\PostModell;    
class postcarseeder extends Seeder
    {
        /**
         * Run the database seeds.
         *
         * @return void
         */
        public function run()
        {

            // Let's truncate our existing records to start from scratch.
            PostModell::truncate();

            $faker = \Faker\Factory::create();

            // And now, let's create a few articles in our database:
            for ($i = 0; $i < 50; $i++) {
                PostModell::create([
                    'title' => $faker->sentence,
                    'body' => $faker->paragraph,
                ]);
              }
        }

上面是我的播种器类,它使用以下命令$this->call(postcarseeder::class);在我的DatabaseSeeder.php中调用,以便我可以运行php artisan db:seed

我得到的错误是 enter image description here

enter image description here

1 个答案:

答案 0 :(得分:4)

您应该使用完整命名空间:

App\PostModell

或者将它添加到播种机类的顶部:

use App\PostModell;
相关问题