crudly/connectly

1.1.2 2020-05-02 21:20 UTC

This package is auto-updated.

Last update: 2022-06-19 12:17:26 UTC


README

Build Status Release License

Store database connections on the database :) Everything encrypted.

$connectly = Connectly::create([
	'name' => 'My connection',
	'config' => [
		'driver' => 'mysql',
		'host' => '127.0.0.1',
		'port' => '3306',
		'database' => 'connectly_test_base',
		'username' => 'connectly_user',
		'password' => 'hunter2',
	],
]);

$myCon = Connectly::where('name', 'My connection')->first();

$connection = $myCon->connect();   // This is a Laravel DB connection

$connection->table('users')->get();

Installation

Use composer.

$ composer require crudly/connectly

Usage

Store a config for a Laravel DB connection in the config property. Laravel's default config/database.php contains some examples and here is a more thorough description.

<?php

use Crudly\Connectly\Connectly;

// ...

$newConnection = new Connectly;

$newConnection->name = 'My other database';

$newConnection->config = [
	'driver' => 'mysql',
	'host' => '127.0.0.1',
	'port' => '3306',
	'database' => 'connectly_test_base',
	'username' => 'connectly_user',
	'password' => 'hunter2',
];

$newConnection->save();

Connectly is an Eloquent model, you can store and retrieve it as such.

<?php

use Crudly\Connectly\Connectly;

// ...

$storedConnectly = Connectly::latest()->first();

//or
$myConnection = Connectly::where('name', 'My other database')->first();

You can use an instance to pop up a new DB connection instance and use it with query builder.

$connection = $myConnection->connect();

$data = $connection->table('posts')->get();