在 laravel 8 中收到名为“Class 'Database\Seeders\App\Models\Product' 未找到”的错误

Getting a error called ''Class 'Database\Seeders\App\Models\Product' not found'' in laravel 8

我目前正在学习在 laravel.But 中创建购物车,当 运行 正在使用种子命令时我收到一个名为 Class 'Database\Seeders\App\Models\Product' 的错误未找到

首先我创建了名为 'Product' 的数据库迁移并添加了那些。

 public function up()
{
    Schema::create('products', function (Blueprint $table) {
        $table->increments('id');
        $table->timestamps();
        $table->string('imagepath');
        $table->string('card-title');
        $table->text('card-text');
        $table->integer('card-price');
        
    });
}

然后我创建了一个名为 'ProductTableSeeder' 的播种机。 之后,我在 Product.php 中的数组中定义了所有这些数组,该数组位于 app\Models

class Product extends Model

{

protected $fillable = ['imagepath','card-title','card-text','card-price'];

}

然后我在'ProductTableSeeder'

中传递数组
public function run()
{
   $product= new App\Models\Product ([
    'imagepath'=>'assets/img/plants/7.jpg',
    'card-title'=>'Books',
    'card-text'=>'aaaaaaaa',
    'card-price'=>'500',
   ]);
   $product->save();

最后在 'DatabaseSeeder' 我调用 ProductTableSeeder 来执行一次 运行 种子命令

 public function run()
{
    $this->call(ProductTableSeeder::class);
}
$product= new App\Models\Product ([

应该是这样的;

$product= new \App\Models\Product ([

在您的 ProductTableSeeder.php 文件中查看