kangangga/laravel-json
Composer 安装命令:
composer require kangangga/laravel-json
包简介
A robust JSON Database Driver for Laravel with Eloquent ORM, Relationships, Hybrid SQL Support, Queue, and Cache drivers.
关键字:
README 文档
README
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
- 🚀 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 & 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
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
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)
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
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
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 <-> 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 & 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
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
You can use the provided test suite to verify the package behavior.
composer test
Credits
License
The MIT License (MIT). Please see License File for more information.
kangangga/laravel-json 适用场景与选型建议
kangangga/laravel-json 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「nosql」 「database」 「orm」 「persistence」 「queue」 「json」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kangangga/laravel-json 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kangangga/laravel-json 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kangangga/laravel-json 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
The DreamFactory(tm) CouchDB Service.
Kinikit - PHP Application development framework MVC component
Store your language lines in the database, yaml or other sources
PHP Database ORM for Symfony1. Do NOT use for new projects: please move to a newest Symfony release and Doctrine2
The CodeIgniter Redis package
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-30