pilat
1 year ago

Search in JSON column does not work with Query Builder and Eloquent Model (but works with raw query)

Posted 1 year ago by pilat

Hi, in Laravel 5.3, I'm trying to use that short syntax for the JSON columns:

$allLeadsEloquent = LeadsCache::where('json->linked_company_id', $companyId)
    ->get();

The result: empty collection. Note: the same result is with Query Builder (DB('table_name')).

Now. I open Debugbar and grab the "Raw query" produced by this code and run this query in the Sequel Pro: there it finds some rows!

Here's the how the raw query looks:

select * from `leads_cache` where `json`->'$."linked_company_id"' = '68743242'

What possibly could go wrong with this?…

Please sign in or create an account to participate in this conversation.