Laravel : Migrations & Seeding for production data

后端 未结 4 932
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 07:11

My application needs a pre registered data set to work. So i need to insert them in the database when i set up the application.

Laravel propose two mechanisms :

4条回答
  •  伪装坚强ぢ
    2020-12-02 07:29

    Laravel development is about freedom. So, if you need to seed your production database and think DatabaseSeeder is the best place to do so, why not?

    Okay, seeder is mainly to be used with test data, but you'll see some folks using it as you are.

    I see this important kind of seed as part of my migration, since this is something that cannot be out of my database tables and artisan migrate is ran everytime I deploy a new version of my application, so I just do

    php artisan migrate:make seed_models_table
    

    And create my seedind stuff in it:

    public function up()
    {
        $models = array(
            array('name' => '...'),
        );
    
        DB::table('models')->insert($models);
    }
    

提交回复
热议问题