Skip to content

Commit

Permalink
Merge pull request #7 from hibob224/non-default-connection
Browse files Browse the repository at this point in the history
Added support for non-default connection
  • Loading branch information
yadakhov committed Aug 28, 2016
2 parents 8abcc88 + a17dc01 commit c465e5c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/InsertOnDuplicateKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function insertOnDuplicateKey(array $data, array $updateColumns =

$data = static::inLineArray($data);

return DB::statement($sql, $data);
return DB::connection(static::getModelConnectionName())->statement($sql, $data);
}

/**
Expand All @@ -60,7 +60,7 @@ public static function insertIgnore(array $data)

$data = static::inLineArray($data);

return DB::statement($sql, $data);
return DB::connection(static::getModelConnectionName())->statement($sql, $data);
}

/**
Expand All @@ -85,7 +85,7 @@ public static function replace(array $data)

$data = static::inLineArray($data);

return DB::statement($sql, $data);
return DB::connection(static::getModelConnectionName())->statement($sql, $data);
}

/**
Expand All @@ -100,6 +100,17 @@ public static function getTableName()
return (new $class())->getTable();
}

/**
* Static function for getting connection name
*
* @return string
*/
public static function getModelConnectionName()
{
$class = get_called_class();
return (new $class())->getConnectionName();
}

/**
* Static function for getting the primary key.
*
Expand Down

0 comments on commit c465e5c

Please sign in to comment.