1#create a laravel seeding file
php artisan make:seeder <seeder file name>
#example
php artisan make:seeder ShopSeeder
2#after seeding file create and seed data added,run this command below to add thos data in database
php artisan db:seed --class=<seeder file name>
#example
php artisan db:seed --class=ShopSeeder
3# if want to add all seeder fill data just run
php artisan db:seed
step-1- php artisan make:seeder yourSeedername
step-2- //add data in inside run function in your new created seeder. eg
$Records = [
['id'=>1, 'name'=>'abc','email'=>'abc@gmail.com'],
['id'=>2, 'name'=>'xyz','email'=>'xyz@gmail.com']
];
YourModel::insert($Records);
//don't forget to use model in top of your seeder
step-3- //register seeder in run function inside Database/Seeders/DatabaseSeers.php as follows
$this->call(yourseeder::class);
step-4- //Now run following command
php artisan db:seed
<?php
use IlluminateDatabaseSeeder;
use IlluminateSupportFacadesDB;
use IlluminateSupportFacadesHash;
use IlluminateSupportStr;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('users')->insert([
'name' => Str::random(10),
'email' => Str::random(10).'@gmail.com',
'password' => Hash::make('password'),
]);
}
}