사용자 입력을 컨트롤러 기능으로 가져와 config/datadata.php
을 업데이트 할 수 있습니다. 드라이버를 가정하면 기본적으로 mysql
, 당신은이 작업을 수행 할 수 있습니다
public function checkDatabaseConnection(Request $request)
{
//update the config
config(['database.connections.mysql' => [
'host' => $request->host,
'username' => $request->username,
'password' => $request->password
]]);
//Check the credentials by calling PDO
try {
DB::connection()->getPdo();
} catch (\Exception $e) {
return redirect()->back()->withErrors(["connection" => "Could not connect to the database. Please check your input."]);
}
}
가 컨트롤러의 상단에
use DB
를 추가하는 것을 잊지 마십시오.
감사합니다. 이미 작동하고 있지만, 이것은 나 자신을 발견 한 것과 같은 해결책이며 작동합니다. 어쨌든 고마워요. – Kaizokupuffball