ybr-nx/laravel-mariadb

Add MariaDB JSON select support to Laravel

Maintainers

👁 ybr-nx

Package info

github.com/ybr-nx/laravel-mariadb

pkg:composer/ybr-nx/laravel-mariadb

Statistics

Installs: 468 191

Dependents: 1

Suggesters: 0

Stars: 96

Open Issues: 4

1.0.20 2019-09-11 05:18 UTC

Requires

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

EUPL-1.2 1dd893432237e28d5d43d1de110be925602dd37d

  • Ingmar Aasoja <ingmar.woop@aasoja.ee>

databasejsonlaravelmariadb

This package is auto-updated.

Last update: 2026-06-11 23:44:35 UTC


README

Add MariaDB JSON support to Laravel. Requires at least MariaDB 10.2.3 (and 10.2.7 to use ->json() migrations)

Install

Using composer:

$ composer require ybr-nx/laravel-mariadb

Configure (only Larvel 5.3 and 5.4)

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',

Added functionality

Migration

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))
Query builder

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"')