Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nikocraft's avatar

has json column type been implemented for mariadb, can I use laravels where and update for json?

I've read this article written on Laravel's handling of json column and possiblity to use where and update functions on json column.

https://mattstauffer.co/blog/new-json-column-where-and-update-syntax-in-laravel-5-3/

Back then it was only possible if Laravel is setup with MySql. I am wondering if MariaDB could be used today with laravels support for json column type.

I found these and it makes me think it should work today but I do not have direct experience with using laravel with where() and update() on json column type and I am considering implementing this in my application, however I want my application's user to be able to use either mysql or mariadb so I need to decide if I want to use these features or not

https://mariadb.com/resources/blog/json-mariadb-102

https://mariadb.com/database/topics/json

0 likes
6 replies
bashy's avatar

10.2 of MariaDB is stable and should be available for people to upgrade to (if they aren't using it already).

JSON wheres are cool but if you just store it as JSON then use a Laravel $cast property, you can explode the JSON into an array when you access the attribute on the rows.

nikocraft's avatar

hi @ybr-nx how does your package make mariadb work with json column? what tricks did you use to make it work? could you explain a littlebit?

also does this work with your package:

DB::table('users') ->where('id', 1) ->update(['meta->wants_newsletter' => false]);

I do not see it mentioned in your documentation.

bashy's avatar

@maxnb It's for older MySQL & MariaDB versions. Basically it explodes the items you pass in and matches it to the column of TEXT which holds JSON.

ybr-nx's avatar

@maxnb Yes. that works. It uses standard JSON_SET() function, so it works without my package also.

Solution was simple. I just translated "column->path" alias back to JSON_EXTRACT and that's mostly all. There were some dirty hacks to make "table.field->json" work.

@bashy Vice verca . It work only on later (or the latest) versions on MariaDB. And by the way also with MySQL 5.7 and up

PS: https://mariadb.com/kb/en/library/mariadb-vs-mysql-compatibility/

  • MariaDB stores JSON as true text, not in binary format as MySQL. The reason is that our JSON functions are much faster than MySQL's so we didn't need to see a need for storing things in binary format as it adds a lot of complexity when manipulating JSON objects.

  • For the same reason, MariaDB's JSON data type is an alias for LONGTEXT.

bashy's avatar

@ybr-nx Oh OK. For manual joins via Eloquent then? Don't do much of that and JSON field works fine for me.

I thought you were adding support to older versions of DB drivers.

Please or to participate in this conversation.