laravel 类 tableseeder 不存在(尽管它确实存在):S
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44028608/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Class tableseeder does not exist (although it really exists) :S
提问by Yasser Moussa
I get this error when trying to migrate plus seeding my database using laravel 5.4
尝试使用 laravel 5.4 迁移和播种我的数据库时出现此错误
[ReflectionException] Class PostTagTableSeeder does not exist
[ReflectionException] 类 PostTagTableSeeder 不存在
In fact the file really exist with correct class name
事实上,该文件确实存在,具有正确的类名
seeds/PostTagTableSeeder.php
种子/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
种子/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);
}
}
I have been struggling to fix this issue but yet i still get the same error
回答by kerrin
Had the same issue and running
有同样的问题并且正在运行
php composer dump-autoload
php composer dump-autoload
as suggested above by Vape and Oliver fixed the issue.
正如上面 Vape 和 Oliver 所建议的那样解决了这个问题。
php artisan migrate:refresh --seed
ran like a charm after that :)
php artisan migrate:refresh --seed
在那之后像魅力一样跑:)
回答by Oladipo
For some, due to your file structure or composer set-up, all you need to run is:
对于某些人来说,由于您的文件结构或 Composer 设置,您只需要运行:
composer dump-autoload
or
或者
composer.phar dump-autoload
Then, retry the seeder script.
然后,重试播种器脚本。