Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Add connection option #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/config.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?php

return array(
/**
* The connection to the database that contains our table (if different then our default).
*/
'connection' => env('DB_CONNECTION', 'mysql'),

/**
* The table that contains the settings column.
*/
Expand Down
13 changes: 11 additions & 2 deletions src/Setting.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down