Target class [UsersTableSeeder] does not exist

Viewed 3699

I am using laravel latest version 7.

When I run php artisan db:seed I am getting the following error:

Illuminate\Contracts\Container\BindingResolutionException

Target class [UsersTableSeeder] does not exist.
3 Answers

After writing your seeder, you have to run composer dump-autoload

Make sure that you have this code in your composer.json:

"autoload": {
    "classmap": [
      "database"
    ],
}

The default laravel installation doesn't have UsersTableSeeder you need to create a new seeder by running

php artisan make:seeder UsersTableSeeder

Laravel doesnt have the UserTableSeeder by default. You can create one by running the following artisan command:

php artisan make:seeder UsersTableSeeder

After running the command you can find the seeder in the database directory. In the run function of the seeder you can create the needed users.

The example below is for my RoleSeeder but it might provide some direction to a suitable solution:

/**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {

        $customer = Role::updateOrCreate(['name' => 'customer']);
        $customerPermissions = [
            'view users',
            'create users',
            'edit users',
            'delete users',
            'view machines',
            'view profile',
            'edit profile',
            'view documents',
        ];
  $customer->givePermissionTo($customerPermissions);
}

I recommand using the updateOrCreate function just because in testing you might want to run a seeder multiple times. This function wil check if the record already exists and will update the record accordingly

Related