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?