类tableseeder不存在(虽然它确实存在):S

Yas*_*ssa 11 php laravel laravel-5.4

我尝试使用laravel 5.4进行迁移加种子数据库时出现此错误

[ReflectionException]类PostTagTableSeeder不存在

事实上,该文件确实存在正确的类名

种子/ 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]);
    }
}
Run Code Online (Sandbox Code Playgroud)

种子/ 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);
    }
}
Run Code Online (Sandbox Code Playgroud)

我一直在努力解决这个问题,但我仍然得到同样的错误在此输入图像描述

ker*_*rin 26

有同样的问题并且正在运行

php composer dump-autoload

如上所述,Vape和Oliver解决了这个问题.

php artisan migrate:refresh --seed 那之后跑得像个魅力:)


Ola*_*ola 7

对于某些文件,由于您的文件结构或作曲者设置而异,您只需要运行:

composer dump-autoload
Run Code Online (Sandbox Code Playgroud)

要么

composer.phar dump-autoload
Run Code Online (Sandbox Code Playgroud)

然后,重试播种器脚本。