本文介绍了Laravel 5 - 工匠种子 [ReflectionException] 类 SongsTableSeeder 不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行 php artisan db:seed 时,我收到以下错误:

When I run php artisan db:seed I am getting the following error:

[ReflectionException] Class SongsTableSeeder does not exist

这是怎么回事?

我的DatabaseSeeder 类:

<?php

use IlluminateDatabaseSeeder;
use IlluminateDatabaseEloquentModel;

class DatabaseSeeder extends Seeder {

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Model::unguard();

        $this->call('SongsTableSeeder');
    }

}

我的SongsTableSeeder 类:

<?php

// Composer: "fzaninotto/faker": "v1.4.0"
use FakerFactory as Faker;
use IlluminateDatabaseSeeder;
use DB;

class SongsTableSeeder extends Seeder {

    public function run()
    {
        $faker = Faker::create();
        $songs = [];
        foreach(range(1, 10) as $index)
        {
            $songs[] = ['title' => $faker->words(rand(1,4))];
        }

        DB::table('songs')->insert($songs);

    }

}

推荐答案

您需要将 SongsTableSeeder 放入 SongsTableSeeder.php 文件中 SongsTableSeeder.php 与DatabaseSeeder.php 文件.

You need to put SongsTableSeeder into file SongsTableSeeder.php in the same directory where you have your DatabaseSeeder.php file.

并且您需要在控制台中运行:

And you need to run in your console:

composer dump-autoload

生成新的类映射然后运行:

to generate new class map and then run:

php artisan db:seed

我刚刚测试过了.它在 Laravel 5 中没有问题

I've just tested it. It is working without a problem in Laravel 5

这篇关于Laravel 5 - 工匠种子 [ReflectionException] 类 SongsTableSeeder 不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-29 06:32