Setup Menus in Admin Panel

  • No products in the cart.


Seeding in Laravel

Seeding concepts:

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


Writing seeder:

To generate a seeder, execute the make:seeder Artisan command. All seeders generated by the framework will be placed in the database/seeds directory:

php artisan make:seeder UsersTableSeeder


code screenshot



use Illuminate\Database\Seeder;

class UsersTableSeeder extends Seeder
* Run the database seeds.
* @return void
public function run()
'username'=> 'root',
'email' => '[email protected]',
'password' => bcrypt('root'),
'full_name' => 'root user',
'contact_no' => '',
'address' => '',
'status' => 1




Running Seeders:

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

php artisan db:seed


Now you will see some data in the users table:



php artisan migrate refresh --seed

If you made some changes in your code this command will seed your database, which will also rollback and re-run all of your migrations. This command is useful for completely re-building your database:




SEE ALL Add a note
Add your Comment

Advanced Course Search Widget

Popular Courses

Course Categories

© PHPhelp. 2002 - 2018 All rights reserved.