Can a record be created when a php artisan migrate is done?

-1

Comrades the question that arises is:

Can a record be created automatically when the migration is created?

That is, when you make the **php artisan migrate** and create the migration within one of the tables, a record is created.

And if this can be done, what is necessary to do.

    
asked by FuriosoJack 29.03.2017 в 18:52
source

1 answer

0

Friend, the migrations are to raise the DB, if you want to create records you must use the seeder de laravel,

try an example:

php artisan make:seeder UsersTableSeeder;

within the UsersTableSeeder file that was created in the database / seeds /

directory
<?php

use Illuminate\Database\Seeder;

class UsersTableSeeder extends Seeder
{

    public function run()
    {

       for($i = 0; $i < 10; $i++){

           \DB::table('users')->insert(array(
               'name'     => "algunNombre",
               'email'    => "algunEmail",
               'password' => \Hash::make('secreto'),
           ));          
       }
   }
}

then you register the seeder in / database / seeds / DatabaseSeeder

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

then you execute the following command in the terminal

composer dump-autoload 

then

php artisan db:seed

here you can review the documentation link

    
answered by 29.03.2017 / 23:02
source