laravel 在尝试php artisan migrate:fresh --seed和php artisan db:seed时不断收到错误

dojqjjoe  于 2023-11-20  发布在  PHP
关注(0)|答案(3)|浏览(124)
php artisan migrate:fresh --seed
    Dropped all tables successfully.
    Migration table created successfully.
    Migrating: 2014_10_12_000000_create_users_table
    Migrated:  2014_10_12_000000_create_users_table (388.12ms)
    Migrating: 2014_10_12_100000_create_password_resets_table
    Migrated:  2014_10_12_100000_create_password_resets_table (664.45ms)
    Migrating: 2014_10_12_200000_add_two_factor_columns_to_users_table
    Migrated:  2014_10_12_200000_add_two_factor_columns_to_users_table (125.81ms)
    Migrating: 2019_08_19_000000_create_failed_jobs_table
    Migrated:  2019_08_19_000000_create_failed_jobs_table (456.85ms)
    Migrating: 2019_12_14_000001_create_personal_access_tokens_table
    Migrated:  2019_12_14_000001_create_personal_access_tokens_table (1,087.48ms)
    Migrating: 2021_06_07_082644_create_sessions_table
    Migrated:  2021_06_07_082644_create_sessions_table (2,139.29ms)
    
       Illuminate\Contracts\Container\BindingResolutionException 
    
      Target class [Database\Seeders\UsersTableSeeder] does not exist.
    
      at vendor\laravel\framework\src\Illuminate\Container\Container.php:879
        875▕
        876▕         try {
        877▕             $reflector = new ReflectionClass($concrete);
    
      1   D:\vendor\laravel\framework\src\Illuminate\Container\Container.php:877
          ReflectionException::("Class "Database\Seeders\UsersTableSeeder" does not exist")
    
      2   D:\vendor\laravel\framework\src\Illuminate\Container\Container.php:877
    -kelompok-7\vendor\laravel\framework\src\Illuminate\Container\Util.php:40
          Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()

UserTableSeeder.php

<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;

class UserTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        User::factory()->create([
            'name'      =>  'Admin',
            'email'     =>  '[email protected]',
            'password'  =>  bcrypt('password');
            'type'      =>  User::ADMIN,
        ]);

        User::factory()->count(5)->create();
    }
}

字符串
我应该怎么做来修复类“Database\Seeders\User”找不到?我已经尝试了migrate fresh和db:seed,但它不工作.我怎么才能让用户工作?我需要一些帮助.我需要让它长,因为我一直得到一个“它看起来像你的帖子主要是代码;请添加一些更多的细节”.

r7knjye2

r7knjye21#

该错误是因为没有名为“UsersTableSeeder”的类,而类名是“UserTableSeeder”-没有“S”。因此,请检查Database\Seeders中的DatabaseSeeder.php并修改它,然后再次运行命令,它将工作。

rkkpypqq

rkkpypqq2#

在DatabaseSeeder.php中更改run()中的内容,

public function run()
    {
        $this->call([
            UsersTableSeeder::class,
        ]);
    }

字符串

public function run()
    {
        $this->call([
            UserTableSeeder::class,
        ]);
    }

iugsix8n

iugsix8n3#

你可能忘了输入这个。

use App\Models\User;

字符串
希望这将工作。

相关问题