Skip to content

Undefined index: operator - whereJsonContains #176

Closed
@dmason30

Description

@dmason30

Describe the bug
We get this error when using whereJsonContains on a JSON (MySQL) database column type.

Eloquent Query
Please provide the complete eloquent query that caused the bug, for example:

$model::whereJsonContains('target_currencies', $target_currency_id)->get();

Stack Trace

37
ErrorException 
…/vendor/genealabs/laravel-model-caching/src/CacheKey.php102
36
Illuminate\Foundation\Bootstrap\HandleExceptions handleError
…/vendor/genealabs/laravel-model-caching/src/CacheKey.php102
35
GeneaLabs\LaravelModelCaching\CacheKey getTypeClause
…/vendor/genealabs/laravel-model-caching/src/CacheKey.php262
34
GeneaLabs\LaravelModelCaching\CacheKey getOtherClauses
…/vendor/genealabs/laravel-model-caching/src/CacheKey.php167
33
GeneaLabs\LaravelModelCaching\CacheKey GeneaLabs\LaravelModelCaching\{closure}
[internal]0
32
 array_reduce
…/vendor/laravel/framework/src/Illuminate/Support/Collection.php1313
31
Illuminate\Support\Collection reduce
…/vendor/genealabs/laravel-model-caching/src/CacheKey.php170
30
GeneaLabs\LaravelModelCaching\CacheKey getWhereClauses
…/vendor/genealabs/laravel-model-caching/src/CacheKey.php36
29
GeneaLabs\LaravelModelCaching\CacheKey make
…/vendor/genealabs/laravel-model-caching/src/Traits/Caching.php76
28
GeneaLabs\LaravelModelCaching\CachedBuilder makeCacheKey
…/vendor/genealabs/laravel-model-caching/src/CachedBuilder.php86

Environment

  • PHP: 7.1.20
  • OS: Ubuntu 14.04
  • Laravel: 5.6.*
  • Model Caching: 0.3.1

Additional Info
Args being passed to:

33 GeneaLabs\LaravelModelCaching\CacheKey GeneaLabs\LaravelModelCaching\{closure}

From the stack trace above are:

array:5 [
  "type" => "JsonContains"
  "column" => "target_currencies"
  "value" => 1
  "boolean" => "and"
  "not" => false
]

This json function does not exist in <= 5.5:
https://laravel.com/docs/5.5/queries#json-where-clauses

The whereJsonContains and whereJsonDoesntContain appears to have been added in 5.6
https://laravel.com/docs/5.6/queries#json-where-clauses

Finally, I am not using 5.7 yet but there appears to be a new whereJsonLength method.
https://laravel.com/docs/5.7/queries#json-where-clauses

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions