Skip to content

Commit

Permalink
Added support for non-default connection
Browse files Browse the repository at this point in the history
  • Loading branch information
hibob224 committed Aug 28, 2016
1 parent 8abcc88 commit a17dc01
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 a17dc01

Please sign in to comment.