Laravel: 如果连接迁移

Laravel: migrate if connection

我的项目是一个多数据库项目。一些迁移文件我必须 运行 在所有数据库上,一些在一个或两个数据库上。我的问题是:如何调查连接名称?

所以如果我的迁移文件是这样的

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Migrations\Migration;

class MigrationFile extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up(){

        if($database == 'myseconddatabase') {

          //code

        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down(){
        Schema::dropIfExists('users');
    }
}

然后我给出命令php artisan migrate --database=myfirstdatabase

如何将值'myfirstdatabase'赋给$database变量?

正在连接 config/database。php

无论您要做什么,都可以使用 DB::connection, get 选项对此进行了演示。

$pvArray = DB::connection('myconn_mysql')->table('products')->select('id')->get();