How to Create Database Seeder in Laravel?
This tutorial is for How to Create Database Seeder in Laravel? Laravel database seeder useful we can include just testing information on our database table. Database seed is extremely useful because testing with various data allows you to likely detect bugs.
Create Database Seeder in Laravel follow this steps
Create Seeder
php artisan make:seeder UsersDataSeeder
#database/seeds/UsersDataSeeder.php
use Illuminate\Database\Seeder;
use App\User;
class UserDataSeeder extends Seeder
{
public function run()
{
DB::table('users')->insert([
'name' => 'devnote',
'email' => 'devnote@gmail.com',
'password' => bcrypt('devnote@016'),
'created_at' => now(),
]);
}
}
Run bellow command :
composer dump-autoload
Run Seeder
php artisan db:seed --class=UsersDataSeeder
=== OR ===
#database/seeds/DatabaseSeeder.php
public function run()
{
$this->call(UserDataSeeder::class); //added
}
php artisan db:seed