web-dev-qa-db-ja.com

クラスtableseederは存在しません(実際には存在しますが):S

laravel 5.4を使用してデータベースをシードおよび移行しようとすると、このエラーが発生します

[ReflectionException]クラスPostTagTableSeederが存在しません

実際、ファイルは正しいクラス名で実際に存在します

seeds/PostTagTableSeeder.php

<?php

use Illuminate\Database\Seeder;
use App\Tag;
use App\Post;

class PostTagTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Model::unguard();
        //DB::table('post_tag')->delete();

        $tag1       = Tag::find(1);
        $tag2       = Tag::find(2);
        $tag3       = Tag::find(3);
        $tag4       = Tag::find(4);
        $post1      = Post::find(1);
        $post2      = Post::find(2);
        $post3      = Post::find(3);
        $post4      = Post::find(4);
        $post5      = Post::find(5);
        $post6      = Post::find(6);
        $post7      = Post::find(7);
        $post8      = Post::find(8);
        $post9      = Post::find(9);
        $post10     = Post::find(10);
        $post11     = Post::find(11);
        $post12     = Post::find(12);
        $post13     = Post::find(13);
        $post14     = Post::find(14);
        $post15     = Post::find(15);

        $post1->tags()->attach([$tag1->id,$tag2->id,$tag3->id]);
        $post2->tags()->attach([$tag2->id,$tag4->id]);
        $post3->tags()->attach([$tag2->id,$tag3->id,$tag4->id]);
        $post4->tags()->attach([$tag4->id]);
        $post5->tags()->attach([$tag2->id]);
        $post6->tags()->attach([$tag2->id]);
        $post7->tags()->attach([$tag2->id]);
        $post8->tags()->attach([$tag1->id,$tag4->id]);
        $post9->tags()->attach([$tag1->id,$tag4->id]);
        $post10->tags()->attach([$tag3->id]);
        $post11->tags()->attach([$tag1->id]);
        $post12->tags()->attach([$tag1->id]);
        $post13->tags()->attach([$tag3->id]);
        $post14->tags()->attach([$tag1->id,$tag2->id,$tag4->id]);
        $post15->tags()->attach([$tag1->id,$tag2->id,$tag4->id]);
    }
}

seeds/DatabaseSeeder.php

<?php

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $this->call(UsersTableSeeder::class);
        $this->call(AdminsTableSeeder::class);
        $this->call(PostsTableSeeder::class);
        $this->call(CategoriesTableSeeder::class);
        $this->call(CategoryPostTableSeeder::class);
        $this->call(TagsTableSeeder::class);
        $this->call(PostTagTableSeeder::class);
        $this->call(CommentsTableSeeder::class);
    }
}

私はこの問題の修正に苦労してきましたが、それでも同じエラーが発生します enter image description here

15
Yasser Moussa

同じ問題があり、実行されていた

php composer dump-autoload

vapeとOliverによって上記で提案されたように、問題を修正しました。

php artisan migrate:refresh --seedその後は魅力のように走りました:)

31
kerrin

一部の人にとっては、ファイル構造またはcomposer設定により、実行する必要があるのは次のとおりです。

composer dump-autoload

または

composer.phar dump-autoload

次に、シードスクリプトを再試行します。

12
Oladipo