Last active
April 12, 2016 16:25
-
-
Save gpedro/f16ea3191457deb2c4e9a29be52b35f2 to your computer and use it in GitHub Desktop.
Allowing Eloquent execute search in json data-types (pgsql) (Laravel 4x)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?ṕ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