0

I am wondering is there a way to make 10-50 rows as default rows that could be added after migration in database?

In case I need to use php artisan migrate:fresh its pain to add simple values over and over again. Like I have Countries table where I need to add over and over again when I run migrate:fresh...

OR

Can I somehow exclude some tables from others that would be affected with command lines

Like inside create_countries_table:

DO_NOT_TOUCH_THIS_TABLE

Thanks

UPDATE:

Without routes etc. Just by migrations

1 Answers1

0

Laravel has a great system about that, all you need to use database seeders.

For exaple you have a users table and you want to make some users.

First create a seeder using make:seeder command

php artisan make:seeder UsersTableSeeder

Then open your UsersTableSeeder and add these lines

public function run()
    {
        DB::table('users')->insert([
            'name' => str_random(10),
            'email' => str_random(10).'@gmail.com',
            'password' => bcrypt('secret'),
        ]);
    }

Then open your DatabaseSeeder class and add this line

public function run()
{
     $this->call(UsersTableSeeder::class);
}

and run db:seed command

php artisan db:seed

For more further check out the seeding on laravel docs

Teoman Tıngır
  • 2,766
  • 2
  • 21
  • 41