PHPackages                             kangangga/laravel-json - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. kangangga/laravel-json

ActiveLibrary[Database &amp; ORM](/categories/database)

kangangga/laravel-json
======================

A robust JSON Database Driver for Laravel with Eloquent ORM, Relationships, Hybrid SQL Support, Queue, and Cache drivers.

1.0.1(3mo ago)01MITPHPPHP ^8.4CI passing

Since Jan 30Pushed 3mo agoCompare

[ Source](https://github.com/kangangga/laravel-json)[ Packagist](https://packagist.org/packages/kangangga/laravel-json)[ Docs](https://github.com/kangangga/laravel-json)[ RSS](/packages/kangangga-laravel-json/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (14)Versions (2)Used By (0)

Laravel JSON Database
=====================

[](#laravel-json-database)

[![Latest Version on Packagist](https://camo.githubusercontent.com/69fd219d9832d6e1e2626fef3270ba8359a118ee834d7fdd4a3c79837b1deed0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b616e67616e6767612f6c61726176656c2d6a736f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kangangga/laravel-json)[![GitHub Tests Action Status](https://camo.githubusercontent.com/2acd93a9cfea578fa333f597f67aa874dc6945b29457d99e80044ff5cddbc00f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6b616e67616e6767612f6c61726176656c2d6a736f6e2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/kangangga/laravel-json/actions?query=workflow%3Arun-tests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/3212518a46a16610915c2ed4ef12a06b434be1474b76b8f537e2adbef337b55b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b616e67616e6767612f6c61726176656c2d6a736f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kangangga/laravel-json)

A modern, robust, and feature-rich JSON Database driver for Laravel. Perfect for small applications, prototyping, or hybrid setups where you need the flexibility of NoSQL with the power of Laravel Eloquent.

Features
--------

[](#features)

- 🚀 **Zero Config Setup** - Works out of the box with auto-injected configurations.
- Eloquent ORM Support - Full support for Models, Relationships, and Query Scopes.
- 💡 **Hybrid Relations** - Seamlessly relate JSON models with SQL models (MySQL, PostgreSQL, SQLite).
- 🔍 **Powerful Query Builder** - Supports `where`, `orderBy`, `limit`, `offset`, and more.
- 📦 **Cache Driver** - Use JSON files as a high-performance cache store.
- 📨 **Queue &amp; Batching** - Full support for Laravel Queues and Job Batching backed by JSON.
- 💾 **Session Driver** - Store user sessions in JSON files.
- 🔄 **Transactions** - Supports database transactions (commit/rollback).
- �️ **Soft Deletes** - Native support for soft deleting records.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require kangangga/laravel-json
```

That's it! The package automatically registers itself and injects the necessary configurations into Laravel.

Configuration
-------------

[](#configuration)

### Zero Configuration

[](#zero-configuration)

By default, the package assumes sensible defaults. You can start using it immediately by setting your environment variables in `.env`:

```
# Use JSON as the default database connection
DB_CONNECTION=json

# Optional: Use JSON for other services
CACHE_DRIVER=json
QUEUE_CONNECTION=json
SESSION_DRIVER=json
```

### Advanced Configuration (Optional)

[](#advanced-configuration-optional)

If you need to customize storage paths or behavior, you can publish the configuration file:

```
php artisan vendor:publish --tag="json-config"
```

This will create `config/laravel-json.php`. Commonly used options:

```
return [
    'connections' => [
        'json' => [
            'driver' => 'json',
            'database' => env('DB_JSON_DATABASE', database_path('json')), // Storage path
            'prefix' => env('DB_JSON_PREFIX', ''),
        ],
    ],
    // ...
];
```

Usage
-----

[](#usage)

### 1. Eloquent Models

[](#1-eloquent-models)

Create a model that extends `Kangangga\Json\Eloquent\Model`. This model will automatically use the `json` connection.

```
namespace App\Models;

use Kangangga\Json\Eloquent\Model;

class Post extends Model
{
    // The table name corresponds to the JSON filename (e.g., storage/laravel-json/posts.json)
    protected $table = 'posts';

    protected $fillable = ['title', 'content', 'views'];
}
```

Now you can use standard Eloquent method:

```
// Create
$post = Post::create(['title' => 'Hello World', 'views' => 0]);

// Update
$post->update(['views' => 100]);

// Query
$popularPosts = Post::where('views', '>', 50)->orderBy('title')->get();

// Delete
$post->delete();
```

### 2. Query Builder

[](#2-query-builder)

You can use the `DB` facade to interact with JSON data directly.

```
use Illuminate\Support\Facades\DB;

// Insert
DB::connection('json')->table('users')->insert([
    'name' => 'John',
    'email' => 'john@example.com'
]);

// Select
$users = DB::connection('json')->table('users')
    ->where('name', 'like', 'Jo%')
    ->get();
```

### 3. Hybrid Relationships (SQL &lt;-&gt; JSON)

[](#3-hybrid-relationships-sql---json)

One of the most powerful features is the ability to define relationships between JSON models and standard SQL models.

**Example: A JSON `Log` model belonging to a MySQL `User` model.**

```
// App/Models/Log.php (JSON Model)
use Kangangga\Json\Eloquent\Model;

class Log extends Model {
    protected $connection = 'json';

    public function user() {
        // BelongsTo relation to a SQL model
        return $this->belongsTo(User::class);
    }
}

// App/Models/User.php (MySQL Model)
use Illuminate\Database\Eloquent\Model;

class User extends Model {
    protected $connection = 'mysql';

    public function logs() {
        // HasMany relation to a JSON model
        return $this->hasMany(Log::class);
    }
}
```

Usage is seamless:

```
$user = User::find(1);
// Automatically queries the JSON database
$logs = $user->logs;

$log = Log::first();
// Automatically queries the MySQL database
echo $log->user->name;
```

### 4. Queue &amp; Job Batching

[](#4-queue--job-batching)

To use JSON as your queue driver, update your `.env`:

```
QUEUE_CONNECTION=json
```

This supports standard queue features including **Job Batching** (which usually requires database migrations). With this package, batching works out of the box using `job_batches.json`.

```
Bus::batch([
    new ProcessPodcast($podcast),
    new OptimizePodcast($podcast),
])->dispatch();
```

### 5. Cache Driver

[](#5-cache-driver)

To use JSON files for caching (great for persistence across restarts without Redis):

```
CACHE_DRIVER=json
```

```
Cache::put('key', 'value', 600);
$value = Cache::get('key');
```

Testing
-------

[](#testing)

You can use the provided test suite to verify the package behavior.

```
composer test
```

Credits
-------

[](#credits)

- [Angga Saputra](https://github.com/kangangga)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance81

Actively maintained with recent releases

Popularity1

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

101d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6cba84b2843eb70e3471f0853700484f0d1ebf72b9a24ed5984ebf0563804842?d=identicon)[kangangga](/maintainers/kangangga)

---

Top Contributors

[![kangangga](https://avatars.githubusercontent.com/u/34059838?v=4)](https://github.com/kangangga "kangangga (14 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

jsonlaravelpersistencedatabaseormeloquentcachequeuenosqldriverhybridfile-based

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/kangangga-laravel-json/health.svg)

```
[![Health](https://phpackages.com/badges/kangangga-laravel-json/health.svg)](https://phpackages.com/packages/kangangga-laravel-json)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[lacodix/laravel-model-filter

A Laravel package to filter, search and sort models with ease while fetching from database.

17649.9k](/packages/lacodix-laravel-model-filter)[ytake/laravel-couchbase

Couchbase providers for Laravel

3051.9k](/packages/ytake-laravel-couchbase)[wayofdev/laravel-cycle-orm-adapter

🔥 A Laravel adapter for CycleORM, providing seamless integration of the Cycle DataMapper ORM for advanced database handling and object mapping in PHP applications.

3516.7k3](/packages/wayofdev-laravel-cycle-orm-adapter)[giacomomasseron/laravel-models-generator

Generate Laravel models from an existing database

484.2k](/packages/giacomomasseron-laravel-models-generator)[andreagroferreira/laravel-sync-tracker

A Laravel package for tracking entity synchronization status between systems

113.0k](/packages/andreagroferreira-laravel-sync-tracker)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
