CodeBug
CodeBug

Reputation: 25

Laravel get all database connection name

I have multiple database defined in my laravel installation inside database.php and I would like to loop all database and perform the same operation in everyone. Something like this:

foreach ($somethingunknown as $connection){
    DB::connection($connection)->table('users')->where('id','=',1)->delete();
}

What is the best way to get all database name? Maybe if possible something with wildcard support.

Upvotes: 0

Views: 4848

Answers (1)

Alexandre Danault
Alexandre Danault

Reputation: 8682

This:

config('database.connections')

returns an array of all your connections and their settings.

Upvotes: 2

Related Questions