Database Seeding

Submitted by Clivern - 4 years ago

With database seeding you can fill your database with dummy data with simple command. I created code that will fill users table with some data. users table consists of three columns (username,email,biog).

class DatabaseSeeder extends Seeder {

     * Run the database seeds.
     * @return void
      public function run()

        //call uses table seeder class
        //this message shown in your terminal after running db:seed command
        $this->command->info("Users table seeded :)");


class UsersTableSeeder extends Seeder {
       public function run()
         //delete users table records
         //insert some dummy records
             array('username'=>'john','email'=>'','biog'=>'PHP Ninga'),
             array('username'=>'mark','email'=>'','biog'=>'JS Ninga'),
             array('username'=>'Karl','email'=>'','biog'=>'Jquery Ninga'),
             array('username'=>'marl','email'=>'','biog'=>'Not Ninga'),
             array('username'=>'mary','email'=>'','biog'=>'HTML Ninga'),
             array('username'=>'sels','email'=>'','biog'=>'CSS Ninga'),
             array('username'=>'taylor','email'=>'','biog'=>'Laravel Ninga'),


//navigate to laravel root with terminal and run the following command
$php artisan db:seed
comments powered by Disqus