php artisan db:seed не работает Laravel 5

Я читал другие ответы, но ничто не решило мою проблему. Когда я запускаю php artisan db:seed, ничего не происходит, даже ошибки не выдается.
Это мой класс DatabaseSeeder

<?php

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;

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

        // call our class and run our seeds
        $this->call(BearAppSeeder::class);

        // $this->call(UserTableSeeder::class);

        Model::reguard();
    }
}

BearAppSeeder содержит следующий контент.

<?php

use Illuminate\Database\Seeder;

class BearAppSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    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::insert(['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, но это не решило мою проблему. Я новичок в Laravel, поэтому я не слишком много знаю об этом.


person Chaudhry Waqas    schedule 18.08.2015    source источник


Ответы (2)


Я думаю, что класс вашей модели Bear не найден в BearAppSeeder. Итак, поставьте

use App\Bear;

после

use Illuminate\Database\Seeder;

Я надеюсь, что это может помочь

person Kiran Subedi    schedule 22.02.2016
comment
Интересно, почему никто не обновил этот ответ до сих пор. В любом случае, благодарю Вас :). - person Sambhav Pandey; 05.08.2016

Вызовите класс сеялки следующим образом:

 $this->call(App\BearAppSeeder::class);

Используйте имя каталога приложения перед BearAppSeeder::class

person Gurinderapal Singh Batth    schedule 23.09.2017