connection('mysql2') 是我的(工作)第二个数据库连接。
当我第一次迁移时,connection('mysql2') 工作正常,表已创建。
Schema::connection('mysql2')->create('brands', function(Blueprint $table)
{
//...
});
但是当我尝试在我的第二个数据库中播种表时:
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use App\Brands;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
$this->call('BrandsTableSeeder');
$this->command->info("Brands table seeded.");
}
}
class BrandsTableSeeder extends Seeder
{
public function run()
{
DB::connection('mysql2')->table('brands')->delete();
Brands::connection('mysql2')->create(['brand' => 'test']);
}
}
我有:
[BadMethodCallException]
Call to undefined method Illuminate\Database\Query\Builder::connection()