0

What i am doing is, want to create table in another database which is not set in .env file. and i want to do this on controller functionality. And I am using a eloquent model throughtout my project. How to create table with this scenario?

SamD
  • 185
  • 5
  • 22

1 Answers1

0

In addition to the linked question that @szebasztian provided in the comment, take a look at the documentation. You can specify what connection Schema will use to create the table when running a migration in this way:

Schema::connection('foo')->create('users', function ($table) {
    $table->increments('id');
});

foo is the new connection you define in config/database.php. I would personally still add the connection details (host, username, password, etc) to .env for that information.

Jeff Lambert
  • 24,395
  • 4
  • 69
  • 96