Laravel 类别';播种机&x27;找不到

Laravel 类别';播种机&x27;找不到,laravel,Laravel,我已经创建了迁移,并将它们迁移到数据库中。现在可以创建种子了,但是php-artisan-db:seed给出了这个错误Class'Seeder'找不到 如何创建seeder类及其存储位置 我正在学习本教程,现在我们正在“为数据库播种关系” 这是我的DatabaseSeeder.php // app/database/seeds/DatabaseSeeder.php <?php use App\Bear; use App\Tree; use App\Fish; use App\Picnic

我已经创建了迁移,并将它们迁移到数据库中。现在可以创建种子了,但是
php-artisan-db:seed
给出了这个错误
Class'Seeder'找不到

如何创建seeder类及其存储位置

我正在学习本教程,现在我们正在“为数据库播种关系”

这是我的
DatabaseSeeder.php

// app/database/seeds/DatabaseSeeder.php
<?php

use App\Bear;
use App\Tree;
use App\Fish;
use App\Picnic;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{

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

        // call our class and run our seeds
        $this->call('BearAppSeeder');
        $this->command->info('Bear app seeds finished.'); // show information in the command line after everything is run
    }
}

// our own seeder class
// usually this would be its own file
class BearAppSeeder extends Seeder
{

    public function run()
    {

        // clear our database ------------------------------------------
        DB::table('bears')->delete();
        DB::table('fish')->delete();
        DB::table('picnics')->delete();
        DB::table('trees')->delete();
        DB::table('bears_picnics')->delete();

        // seed our bears table -----------------------
        // we'll create three different bears

        // bear 1 is named Lawly. She is extremely dangerous. Especially when hungry.
        $bearLawly = Bear::create(array(
            'name'         => 'Lawly',
            'type'         => 'Grizzly',
            'danger_level' => 8
        ));

        // bear 2 is named Cerms. He has a loud growl but is pretty much harmless.
        $bearCerms = Bear::create(array(
            'name'         => 'Cerms',
            'type'         => 'Black',
            'danger_level' => 4
        ));

        // bear 3 is named Adobot. He is a polar bear. He drinks vodka.
        $bearAdobot = Bear::create(array(
            'name'         => 'Adobot',
            'type'         => 'Polar',
            'danger_level' => 3
        ));

        $this->command->info('The bears are alive!');

        // seed our fish table ------------------------
        // our fish wont have names... because theyre going to be eaten

        // we will use the variables we used to create the bears to get their id

        Fish::create(array(
            'weight'  => 5,
            'bear_id' => $bearLawly->id
        ));
        Fish::create(array(
            'weight'  => 12,
            'bear_id' => $bearCerms->id
        ));
        Fish::create(array(
            'weight'  => 4,
            'bear_id' => $bearAdobot->id
        ));

        $this->command->info('They are eating fish!');

        // seed our trees table ---------------------
        Tree::create(array(
            'type'    => 'Redwood',
            'age'     => 500,
            'bear_id' => $bearLawly->id
        ));
        Tree::create(array(
            'type'    => 'Oak',
            'age'     => 400,
            'bear_id' => $bearLawly->id
        ));

        $this->command->info('Climb bears! Be free!');

        // seed our picnics table ---------------------

        // we will create one picnic and apply all bears to this one picnic
        $picnicYellowstone = Picnic::create(array(
            'name'        => 'Yellowstone',
            'taste_level' => 6
        ));
        $picnicGrandCanyon = Picnic::create(array(
            'name'        => 'Grand Canyon',
            'taste_level' => 5
        ));

        // link our bears to picnics ---------------------
        // for our purposes we'll just add all bears to both picnics for our many to many relationship
        $bearLawly->picnics()->attach($picnicYellowstone->id);
        $bearLawly->picnics()->attach($picnicGrandCanyon->id);

        $bearCerms->picnics()->attach($picnicYellowstone->id);
        $bearCerms->picnics()->attach($picnicGrandCanyon->id);

        $bearAdobot->picnics()->attach($picnicYellowstone->id);
        $bearAdobot->picnics()->attach($picnicGrandCanyon->id);

        $this->command->info('They are terrorizing picnics!');
    }
}


我已经尝试了这里找到的所有答案,还有
composer dump autoload
,但没有乐趣。

您需要确保导入您的类扩展的Lighting
Seeder

使用App\Bear;
使用App\Tree;
使用App\Fish;
使用应用程序\野餐;
使用照明\数据库\播种机;
类DatabaseSeeder扩展了Seeder
{
//代码的其余部分

在你的班级顶端

好的,谢谢。我这样做了,现在我得到了一个新的错误
class'Bear'not found
谢谢,现在我得到了这个
class'App\Bear'not found
更新,我会得到同样的
class'App\Bear'not found
错误。这一行似乎是一个致命的错误
$bearLawly=Bear::create(数组(
我在上面的问题中更新了我的播种机代码。问题可能是我的数据库表名为“bears”而不是“bear”?或者可能是在我的
公共函数run()
,而不是
DB::table('bears')->delete();
我需要数据库名
bears::table('bears')->delete();
?对照
use
指令检查名称空间中CAP的一致性。请参阅以了解可能存在的相同问题。
// app/models/seeder.php
<?php

class Seeder extends Seeder
{

    protected $fillable = [];
    protected $table = 'bear';
}