0

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.

3
  • Likely a typo, but ->where('id,'=',1) is a syntax error, should be ->where('id','=',1) (missing a ' after id) Commented Nov 20, 2019 at 16:27
  • @TimLewis That wasn't he point of the question, but nice catch. Edited. Commented Nov 20, 2019 at 18:36
  • @AlexandreDanault Haha yeah. I could have edited myself (as like I said, figured it was a typo), but I tend to let the asker do that just it case it is, in fact, an error in their code. Thanks for fixing! Commented Nov 20, 2019 at 18:43

1 Answer 1

2

This:

config('database.connections')

returns an array of all your connections and their settings.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.