Skip to content

Commit

Permalink
[11.x] Allow using castAsJson() on non default db connection during
Browse files Browse the repository at this point in the history
test

Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Oct 21, 2024
1 parent 3807ec7 commit 8b2b991
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,23 @@ protected function isSoftDeletableModel($model)
* Cast a JSON string to a database compatible type.
*
* @param array|object|string $value
* @param string|null $collection
* @return \Illuminate\Contracts\Database\Query\Expression
*/
public function castAsJson($value)
public function castAsJson($value, $connection = null)
{
if ($value instanceof Jsonable) {
$value = $value->toJson();
} elseif (is_array($value) || is_object($value)) {
$value = json_encode($value);
}

$value = DB::connection()->getPdo()->quote($value);
$db = DB::connection($connection);

return DB::raw(
DB::connection()->getQueryGrammar()->compileJsonValueCast($value)
$value = $db->getPdo()->quote($value);

return $db->raw(
$db->getQueryGrammar()->compileJsonValueCast($value)
);
}

Expand Down

0 comments on commit 8b2b991

Please sign in to comment.