php artisan make:seeder NameOfTheSeeder
//All Seeders
php artisan db:seed
//One Seeder
php artisan db:seed --class=NameSeeder
php artisan make:seeder UsersTableSeeder
#To create a seeder
php artisan make:seeder CategorySeeder
php artisan make:seeder ArticlesTableSeeder
$ php artisan make:seeder MoviesTableSeeder
<?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'),
]);
}
}
// in DatabaseSeeder.php file
$this->call([
UserSeeder::class,
]);
/**
* Run the database seeders.
*
* @return void
*/
public function run()
{
$this->call([
UserSeeder::class,
PostSeeder::class,
CommentSeeder::class,
]);
}
php artisan db:seed --force
$ php artisan db:seed
namespace DatabaseSeeders;
use AppModelsCategory;
use AppModelsPost;
use AppModelsUser;
use IlluminateDatabaseSeeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
$users = User::factory(2)->create();
$categories = Category::factory(3)->create();
Post::factory(3)->create([
'user_id' => $users[0]->id,
'category_id' => $categories[0]->id
]);
Post::factory(3)->create([
'user_id' => $users[1]->id,
'category_id' => $categories[2]->id
]);
}
}
composer require orangehill/iseed
php artisan iseed my_table