Categories
Laravel

Laravel 8 Target class [TableSeeder] does not exist

Today I am getting this error when I am trying to refresh seed with php artisan migrate:refresh –seed command. Database Seeder class is called another seeder class with $this->call(CmsPagesSeeder::class); But geeting error Target class [CmsPagesSeeder] does not exist.

Finally I have apply follwing solution and now working fine with command php artisan migrate:refresh –seed or php artisan db:seed or php artisan db:seed –class=CmsPagesSeeder

Laravel 8 Seeders and Factories are now need to add namespace at the top of class file.

Example:

STEP: 1

Rename directory database/seeds to database/seeders

STEP: 2

Open composer.json file and change on autoload section.

STEP: 3

Open Database Seeder file database/seeders/DatabaseSeeder.php and add namespace Database\Seeders; on top of page.

STEP: 4

Open your others seeders file and add namespace Database\Seeders; to all seeders class.

STEP: 5
Done! Now run following commands you can see now DB seeder is working fine.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE

Categories
Laravel

Laravel 7.x Generate Database Seeding

Laravel: Generate Seeders

Laravel includes with a simple method of seeding your database with test data using seed classes. All seed classes are stored in the database/seeds directory. We can set any name for Seed classes, but we should follow some sensible convention, such as ProductsTableDataSeeder, etc. By default, a DatabaseSeeder class is defined for you. Using default class, you may use the call method to run other seed classes, allowing you to control the seeding order.

Creating a new module

We can creating a simple module by run the following command to create a module. Replace MODULE_NAME by your desired name.

Also we can create multiple modules in one command like below.

How to Generate Seeders?

We can generate a seeder by the Artisan command make:seeder. All of generated seeders class will be placed in the database/seeds directory:

Calling default DatabaseSeeder with Additional Seeders

Default the DatabaseSeeder class, you may use the call method to execute additional seed classes. Using the call method allows you to break up your database seeding into multiple files so that no single seeder class becomes overwhelmingly large. Enter the name of the seeder classes you want to run:

Laravel: Running Seeders

Once you have done generate your seeder, you may need to regenerate Composers autoloader using the dump-autoload command.

To seed your database now you may use the Artisan command db:seed. By default, the db:seed command runs the DatabaseSeeder class, which may be used to call other seed classes.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE