Ejemplo n.º 1
0
 /**
  * Get a default db value, if any is available
  *
  * @return ConnectionInterface|null A default db value or Null if no default value is available
  */
 public function getDefaultDb()
 {
     // By default, the DB Facade does not return the
     // any actual database connection, but rather an
     // instance of \Illuminate\Database\DatabaseManager.
     // Therefore, we make sure only to obtain its
     // "connection", to make sure that its only the connection
     // instance that we obtain.
     $manager = DB::getFacadeRoot();
     if (!is_null($manager)) {
         return $manager->connection();
     }
     return $manager;
 }
Ejemplo n.º 2
0
 /**
  * Attempt a DB operation - utilising a transaction
  *
  * @param  callable  $callback
  *
  * @return mixed
  */
 public function attempt(callable $callback)
 {
     DB::beginTransaction();
     try {
         $value = $callback(DB::getFacadeRoot());
         DB::commit();
     } catch (\Exception $e) {
         DB::rollBack();
         throw $e;
     }
     return $value;
 }
Ejemplo n.º 3
0
 /**
  * Setup before each test.
  */
 public function setUp()
 {
     parent::setUp();
     $this->options = new OptionsService(DB::getFacadeRoot(), 'options');
 }
Ejemplo n.º 4
0
 /**
  * Get a default db manager value, if any is available
  *
  * @return DatabaseManager|null A default db manager value or Null if no default value is available
  */
 public function getDefaultDbManager()
 {
     return DB::getFacadeRoot();
 }
Ejemplo n.º 5
0
 /**
  * Get a database schema builder instance for the
  * given connection.
  *
  * @param string $name
  *
  * @return \Illuminate\Database\Schema\Builder|null Returns null when no database connection is available
  */
 public function connection($name)
 {
     // We do this check to ensure that a connection is available
     $manager = DB::getFacadeRoot();
     if (!is_null($manager) && !is_null($manager->connection())) {
         return Schema::connection($name);
     }
     return $manager;
 }