Laravel Mariadb

ybr-nx/laravel-mariadb image

Laravel Mariadb stats

Downloads
298.1K
Stars
95
Open Issues
5
Forks
6

View on GitHub →

Add MariaDB JSON select support to Laravel

laravel-mariadb

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

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Ybr Nx Laravel Mariadb Related Articles

Bulk Job Dispatching with Bus::bulk() in Laravel 13.13 image

Bulk Job Dispatching with Bus::bulk() in Laravel 13.13

Read article
Detect and Resolve Laravel Schema Drift with MigrAlign image

Detect and Resolve Laravel Schema Drift with MigrAlign

Read article
Attach Addresses to Any Eloquent Model with Laravel Addressable image

Attach Addresses to Any Eloquent Model with Laravel Addressable

Read article
Cache Failover and Deferred Queue in Laravel 12.35 image

Cache Failover and Deferred Queue in Laravel 12.35

Read article
The Hidden Cost of MySQL Defaults in Laravel Apps image

The Hidden Cost of MySQL Defaults in Laravel Apps

Read article
Model Resource Helper Functions in Laravel 12.7 image

Model Resource Helper Functions in Laravel 12.7

Read article
The Certification of Competence for Laravel logo

The Certification of Competence for Laravel

A community-driven, proctored assessment across 4 levels designed to validate real-world Laravel knowledge, from Junior to mastery-level Artisan. Official Vue.js, Official Nuxt, Angular, React, JS certifications also available.

The Certification of Competence for Laravel
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Celebian logo

Celebian

Celebian is a social media marketing agency specializing in helping their clients go viral on TikTok. Whether you're looking to reach a bigger audience or gain more Tiktok followers, likes, and views, they've got you covered.

Celebian
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum