I have installed Lumen 5.5 and configured .env :
APP_ENV=local
APP_DEBUG=true
APP_KEY=2gh4RD89kWa87clEs6Vhjso3XhsFo3dR
APP_TIMEZONE=UTC
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=XXXXXX
DB_USERNAME=XXXXXX
DB_PASSWORD=XXXXXX
CACHE_DRIVER=memcached
QUEUE_DRIVER=sync
and created a model using Eloquent :
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Test extends Model {
public $timestamps = false;
protected $connection = 'foo';
}
Now there is no documention on the official site to configure multiple DB connection in .env file. My single connection is working perfectly fine but now I need to add another DB connection details.
What I have tried so far :
Created db config file as
app/config/database.phpwith multiple db details but my setup doesn't get affected whatever i write in that file. It's only using.envto get connection details.Tried to add multiple DB connection details in
.envfile like :DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=XXXXXX DB_USERNAME=XXXXXX DB_PASSWORD=XXXXXX
FOO_DB_CONNECTION=mysql FOO_DB_HOST=127.0.0.1 FOO_DB_PORT=3306 FOO_DB_DATABASE=FOOXXXXXX FOO_DB_USERNAME=FOOXXXXXX FOO_DB_PASSWORD=FOOXXXXXX
DB_CONNECTION_FOO=mysql DB_HOST_FOO=127.0.0.1 DB_PORT_FOO=3306 DB_DATABASE_FOO=FOOXXXXXX DB_USERNAME_FOO=FOOXXXXXX DB_PASSWORD_FOO=FOOXXXXXX
But it just keep giving me this error :
(1/1) InvalidArgumentException
Database [foo] not configured.
I have tried everything I found on Google.
The way I configured in my project (it is in Lumen 5.4) is as below:
in the
config/database.phpI have created 2 connections with 2 different names and each connection points to a different env variable for db host/database/username/password/schema. If this doesn't help, post your database.php file.