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

Viewed 343

I am currently learning to create a shop cart in laravel.But when running the seed command im getting a error called Class 'Database\Seeders\App\Models\Product' not found

First i created the database migration called 'Product' and added those.

 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');
        
    });
}

Then i created a seeder called 'ProductTableSeeder'. After that i defined all of them in a array in Product.php which is in app\Models

class Product extends Model

{

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

}

Then i pass the array in '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();

Finally in 'DatabaseSeeder' i called the ProductTableSeeder to execute once i run the seed command

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

This should be like this;

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

Check it out on your ProductTableSeeder.php file

Related