I get this error when trying to migrate plus seeding my database using laravel 5.4
[ReflectionException] Class PostTagTableSeeder does not exist
In fact the file really exist with correct class name
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);
}
}
I have been struggling to fix this issue but yet i still get the same error
Had the same issue and running
composer dump-autoload
as suggested above by Vape and Oliver fixed the issue. Then re-run the migrations
php artisan migrate:refresh --seed
or the seeder
php artisan db:seed
and it'll run like a charm.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With