mercredi 17 février 2016

Laravel Check if can connect to DB

I'am trying to prevent query to DB if connection is not possible. Basically if can't connect and app_debug = false it jusst throws 500 error and if app_debug = true shows error trace.

I need when ther is no connection to DB just return an empty array Until now I tried this:

if(config('database.connections.custom')){{
   if(DB::connection('custom')->getDatabaseName()){
      //ther is connection can query DB
   }else{
      return [];
   }
}

But still I get a 500 error, any suggestions? (laravel way, whithout using PDO or mysqli_connect



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire