When selecting data from a JSON column and using MySQL data is returned quoted.
If database driver is changed to Postgres then it's ok.
Mysql docs suggests using ->> operator but that doesn't work with eloquent.
MyModel::where(
'level0->level1->myString',
'like',
'%'.strtoupper($searchTerm).'%'
)
->select([
'level0->level1->string1 as name',
])
->get()
->toArray();The ->> operator does work:
->select(['level0->>level1->>string1 as name'])
The
->>operator does work:->select(['level0->>level1->>string1 as name'])
Yes, this works for MySql.
But if I then switch to Postgres it doesn't return any result since "->>" on first element returns text instead of object.
You want to use the same code with different databases? You'll have to use something like if(DB::connection()->getName() == 'mysql') { } to execute different queries.
You want to use the same code with different databases? You'll have to use something like
if(DB::connection()->getName() == 'mysql') { }to execute different queries.
I thought about it but isn't the point of using orm so I don't have to?
It propertly transforms 'column->level0->property_name as name to postgres syntax - 'column->level0->>property_name as name and also partially to mysql, which is column`->'$."level0"."property_name"' as `name.
I needs to change -> to ->> for mysql version.
The MySQL implementation behaves differently for historical reasons. I agree that this is not ideal. I'll look into a PR.
The MySQL implementation behaves differently for historical reasons. I agree that this is not ideal. I'll look into a PR.
Ok, thank you.
Will be fixed in Laravel 5.8.
Please close the issue.
Most helpful comment
Will be fixed in Laravel 5.8.