DEV Community

Cover image for How to insert seed data or dummy data for Laravel Application.
Osman Forhad
Osman Forhad

Posted on

How to insert seed data or dummy data for Laravel Application.

Application Database however I want.
After that I modify default Database Seeder class and add a database insert statement into run method.
So, what I was done into Database Seeder Class.?
It’s looks like below.
.
<?php
User Illuminate\Databse\Seeder;
User Illuminate\Support\Facades\DB;
User Illuminate\ Support \ Facades\Hash;
User Illuminate\ Support\str;
Class DatabseSeeder extends Seeder {
public function run {
DB: table(‘users’)->insert ([
‘name’ => ‘admin’,
‘email’ => ‘admin@crm.com’,
‘password’ => bcrypt(‘@dmin&0960’),
‘position_title’ => ‘sales_manager’,
‘is_admin’ => 1,
‘is_admin’ => 1,
]);
}//end run method
}//end of the class
?>
.
Once I have written Seeder, Then I need to regenerate Composer autoloader using the dump-autoload command.
For Running Seeder, I was Run
composer dump-autoload on my terminal
Now I am ready to use db: seed Artisan Command, but before that I decide to refresh my database tables for confirm insert new data.
For this purpose, I was Run php artisan migrate: refresh command on my terminal.
Which was drop all tables and re-run all of my Laravel Applications migrations.
Note: This command is useful for completely re-build Laravel Application Database.
Now I have to all set to run db: seed Artisan command. So finally, I was run php artisan db: seed on my terminal.
Finally, I was Successfully inserted dummy data for my Application using Laravel Database: Seeding method.
that's it.
.
Happy Coding.
osman forhad
Mobile & Web Application Developer💻

Top comments (0)