laravel操作mysql中JSON类型的字段
MySQL文档:https://dev.mysql.com/doc/refman/5.7/en/json-search-functions.html#function_json-extract
MySQL 5.7.8开始支持 json类型. laravel也从5.3开始加入了json类型的支持
查看MySQL版本
[root@bogon]# mysql -V
mysql Ver 14.14 Distrib 5.7.32, for Linux (x86_64) using EditLine wrapper
mysql> select version();
+------------+
| version() |
+------------+
| 5.7.32-log |
+------------+
1 row in set (0.00 sec)
Navicat在15这个版本可以查看到,低版本不显示json类型的字段。
mysql> select * from json_demo;
+----+---------------------------------------+
| id | attr |
+----+---------------------------------------+
| 1 | {"尺寸": "XXL", "颜色": "黑色"} |
| 2 | {"尺寸": "XL", "颜色": "白色"} |
+----+---------------------------------------+
2 rows