Skip to content

Instantly share code, notes, and snippets.

@gpedro
Last active April 12, 2016 16:25
Show Gist options
  • Save gpedro/f16ea3191457deb2c4e9a29be52b35f2 to your computer and use it in GitHub Desktop.
Save gpedro/f16ea3191457deb2c4e9a29be52b35f2 to your computer and use it in GitHub Desktop.
Allowing Eloquent execute search in json data-types (pgsql) (Laravel 4x)
<?ṕhp
// /vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php
protected $unwrappedTypes = array(
'->>', '->', '#>', '#>>'
);
/**
* Compile a basic where clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
protected function whereBasic(Builder $query, $where)
{
$value = $this->parameter($where['value']);
foreach ($this->unwrappedTypes as $types) {
if (str_contains($where['column'], $types)) {
return $where['column'] . ' ' . $where['operator'] . ' ' . $value;
}
}
return $this->wrap($where['column']).' '.$where['operator'].' '.$value;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment