Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
How to check database connection array

So basically i'm building an application where the customer wants to connect to his own databases, and I made a form where he can submit his credentials

connectionForm: this.$inertia.form({
                driver: 'mysql',
                name: '',
                host: '',
                port: 3306,
                username: '',
                password: '',
                database: '',
                charset  : 'utf8',
                collation: 'utf8_unicode_ci',
                prefix: '',

            })

Array received in laravel controller

array:10 [▼
  "driver" => "mysql"
  "name" => "Connection"
  "host" => "127.0.01"
  "port" => 3306
  "username" => "root"
  "password" => null
  "database" => "clinic"
  "charset" => "utf8"
  "collation" => "utf8_unicode_ci"
  "prefix" => null
]

And I want to create a function to check if the submitted database credentials can make a connection to his database, so far I haven't found a way to do it by passing the credentials array. I've tried this way

if (DB::connection($request->validated())->getDatabaseName())
        {
            ray('The connection was successfull');
            return 'Connected to the DB: ' . DB::connection('myDamnDbConnection')-getDatabaseName();
        }

but it requires a string, not an array. Is there any way to do this?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Add the database configuration to your config as a new entry and then use that:

config([ 'database.connections.temp' => $request->validated() ]);
DB::connection('temp')->connect(); // Would throw an exception if it fails 
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda