Package Data | |
---|---|
Maintainer Username: | ybr-nx |
Maintainer Contact: | ingmar@aasoja.ee (Ingmar Aasoja) |
Package Create Date: | 2017-08-17 |
Package Last Update: | 2019-09-11 |
Home Page: | |
Language: | PHP |
License: | EUPL-1.2 |
Last Refreshed: | 2024-11-23 03:05:39 |
Package Statistics | |
---|---|
Total Downloads: | 370,940 |
Monthly Downloads: | 5,876 |
Daily Downloads: | 95 |
Total Stars: | 95 |
Total Watchers: | 4 |
Total Forks: | 7 |
Total Open Issues: | 4 |
Add MariaDB JSON support to Laravel. Requires at least MariaDB 10.2.3 (and 10.2.7 to use ->json() migrations)
Using composer:
$ composer require ybr-nx/laravel-mariadb
Include MariaDBServiceProvider in your config/app.php:
'providers' => [
/*
* Package Service Providers...
*/
YbrNX\MariaDB\MariaDBServiceProvider::class,
]
set driver in database configuration to mariadb
'defaultconnection' => [
'driver' => 'mariadb',
Adds needed validation to json fields during migrations
$table->json('field') //CHECK (JSON_VALID(field))
$table->json('field')->nullable() //CHECK (field IS NULL OR JSON_VALID(field))
Builds json select statements to work with MariaDB
$query->where('somejson->something->somethingelse', 2)
DB::table('sometable')->select('sometable.somedata', 'sometable.somejson->somedata as somejsondata')
And also JSON_SET() works in MariaDB as in MySQL 5.7
DB::table('sometable')->where('somejson->somedata', $id)->update(['somejson->otherdata' => 'newvalue']);
NB There is bug in MariaDB < 10.2.8 JSON_EXTRACT() behaviour function. It's fixed in MariaDB 10.2.8: https://jira.mariadb.org/browse/MDEV-12604
//works with string in MySQL & MariaDB 10.2.8
$query->where('somejson->something->somethingelse', 'somedata')
//works with string in MariaDB < 10.2.8
$query->where('somejson->something->somethingelse', '"somedata"')