本文整理汇总了PHP中Illuminate\Support\Facades\DB::disconnect方法的典型用法代码示例。如果您正苦于以下问题:PHP DB::disconnect方法的具体用法?PHP DB::disconnect怎么用?PHP DB::disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\DB
的用法示例。
在下文中一共展示了DB::disconnect方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tearDown
public function tearDown()
{
$this->beforeApplicationDestroyed(function () {
DB::disconnect();
});
parent::tearDown();
}
示例2: handle
/**
* Sets the connection's database to the current user database
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
// Get the current authenticated user
$user = Auth::user();
// Close any connection made before to avoid conflicts
DB::disconnect('tenantdb');
// Set the connection's database to the user's own database
Config::set('database.connections.tenantdb.database', storage_path() . '/' . $user->database);
return $next($request);
}
示例3: create
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
public function create(array $data)
{
$user = User::create(['name' => $data['name'], 'email' => $data['email'], 'database' => $data['name'] . '.sqlite', 'password' => bcrypt($data['password'])]);
// Create the new user sqlite database
Storage::put($user->database, '');
// Close any connection made with tenantdb
DB::disconnect('tenantdb');
// Set the tenant connection to the users own database
Config::set('database.connections.tenantdb.database', storage_path() . '/' . $user->database);
// Run migrations for the new db
Artisan::call('migrate', ['--database' => 'tenantdb', '--path' => 'database/migrations/tenant']);
return $user;
}
示例4: getObras
/**
* Obtiene las obras de un usuario cadeco de todas las bases de datos definidas
*
* @param $idUsuario
* @return Collection|Obra
*/
public function getObras($idUsuario)
{
$obrasUsuario = new Collection();
$basesDatos = BaseDatosCadeco::where('activa', true)->orderBy('nombre')->get();
foreach ($basesDatos as $bd) {
$this->config->set('database.connections.cadeco.database', $bd->nombre);
$usuarioCadeco = $this->getUsuarioCadeco($idUsuario);
$obras = $this->getObrasUsuario($usuarioCadeco);
foreach ($obras as $obra) {
$obra->databaseName = $bd->nombre;
$obrasUsuario->push($obra);
}
DB::disconnect('cadeco');
}
$perPage = 10;
$currentPage = Paginator::resolveCurrentPage();
$currentPage = $currentPage ? $currentPage : 1;
$offset = $currentPage * $perPage - $perPage;
$paginator = new LengthAwarePaginator($obrasUsuario->slice($offset, $perPage), $obrasUsuario->count(), $perPage);
return $paginator;
}
示例5: disconnect
public function disconnect($site_id)
{
DB::disconnect($site_id . '_production');
}