尝试使用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]);
}
}
种子/ 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);
}
}
答案 0 :(得分:16)
有同样的问题并且正在运行
php artisan migrate:refresh --seed
QTableWidgetItem
之后就像魅力一样:)
答案 1 :(得分:1)
编写播种器后,可能需要使用dump-autoload命令here
重新生成Composer的自动加载器。composer dump-autoload
现在,您可以使用db:seed Artisan命令来播种数据库。
答案 2 :(得分:0)
对于某些文件,由于您的文件结构或作曲者的设置,您只需要运行:
composer dump-autoload
或
composer.phar dump-autoload
然后,重试种子脚本。