From fb34fb189b0a13919b9c923cfd26c72237f724c9 Mon Sep 17 00:00:00 2001 From: Robert Lanzas Date: Mon, 8 May 2017 11:56:48 -0500 Subject: [PATCH] Add connection option --- config/config.php | 5 +++++ src/Setting.php | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) mode change 100644 => 100755 config/config.php mode change 100644 => 100755 src/Setting.php diff --git a/config/config.php b/config/config.php old mode 100644 new mode 100755 index 2bd2e40..141eb06 --- a/config/config.php +++ b/config/config.php @@ -1,6 +1,11 @@ env('DB_CONNECTION', 'mysql'), + /** * The table that contains the settings column. */ diff --git a/src/Setting.php b/src/Setting.php old mode 100644 new mode 100755 index c2d37a7..51917d0 --- a/src/Setting.php +++ b/src/Setting.php @@ -5,6 +5,14 @@ class Setting { + /** + * The connection name. + * Configured by the developer (see config/config.php for default). + * + * @var string + */ + protected $connection = ''; + /** * The table name. * Configured by the developer (see config/config.php for default). @@ -77,6 +85,7 @@ class Setting { */ public function __construct() { + $this->connection = config('laravel-user-settings.connection'); $this->table = config('laravel-user-settings.table'); $this->column = config('laravel-user-settings.column'); $this->custom_constraint = config('laravel-user-settings.custom_constraint'); @@ -200,7 +209,7 @@ public function save($constraint_value = null) $constraint_query = $this->getConstraintQuery($constraint_value); - $res = \DB::table($this->table) + $res = \DB::connection($this->connection)->table($this->table) ->whereRaw($constraint_query) ->update($update); @@ -220,7 +229,7 @@ public function load($constraint_value = null) { $constraint_value = $this->getConstraintValue($constraint_value); $constraint_query = $this->getConstraintQuery($constraint_value); - $json = \DB::table($this->table) + $json = \DB::connection($this->connection)->table($this->table) ->whereRaw($constraint_query) ->value($this->column);