My project is not seeding properly please guide

  Fri 09 / 06 / 2023

  Posted by: wajahat

Category : Laravel

Tags : laravel , backend

Description

Error 


  Class "Database\Seeders\Products" not found


  at D:\Xampp\htdocs\E-comShop\E-comShop\database\seeders\DatabaseSeeder.php:21

     17▕      */

     18▕     public function run()

     19▕     {

     20▕

  ➜  21▕         Products::factory(10) -> create();

     22▕     }

     23▕ }

     24▕


  1   D:\Xampp\htdocs\E-comShop\E-comShop\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:36

      Database\Seeders\DatabaseSeeder::run()


  2   D:\Xampp\htdocs\E-comShop\E-comShop\vendor\laravel\framework\src\Illuminate\Container\Util.php:41

      Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()


View Code
                        <?php

namespace Database\Seeders;

// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Database\factories\ProductsFactory;
//use app\Models\Products;


class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {

        Products::factory(10) -> create();
    }
}
                
  Answered by CDL

You forgot import the model at the top. Add your Products model at the top resolve this issue.

Syntax:

~~~

App\Models\Products;

~~~

  Comment   Share
0 Likes   0 Comments