Download the PHP package echoaro/laravel-json-mutator without Composer
On this page you can find all versions of the php package echoaro/laravel-json-mutator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-json-mutator
Laravel JSON Mutator
A powerful Laravel package for easy JSON metadata management with custom casts, dot notation support, and fluent interface.
Features
- Easy JSON Management: Simple and intuitive API for managing JSON metadata
- Dot Notation Support: Access nested data using dot notation (e.g.,
user.profile.name) - Fluent Interface: Chain methods for better readability
- Type Safety: Full type hints and return type declarations
- Array Access: Use array syntax for accessing metadata
- Laravel Integration: Seamless integration with Laravel Eloquent models
- Laravel 11+ & 12 Support: New Attribute-based cast for better compatibility
- Comprehensive Testing: Full test coverage with PHPUnit
Quick Links
- 📋 Documentation - Full documentation
- 🐛 Issues - Report bugs
- 💡 Discussions - Ask questions
Installation
You can install the package via Composer:
The package will automatically register itself with Laravel.
Requirements
- PHP: ^8.2
- Laravel: ^10.0|^11.0|^12.0
Basic Usage
1. Add the Cast to Your Model
Option 1: Traditional Cast (Laravel 10+)
Option 2: Attribute Cast (Laravel 11+ Recommended)
2. Use the metadata (column name) in Your Code
Advanced Usage
Merging Data
Working with Collections
Static Methods
Fluent Interface
Database Migration
Create a migration to add a metadata column:
Available Methods
JsonMutator Methods
| Method | Description |
|---|---|
get($key, $default = null) |
Get a value using dot notation |
set($key, $value) |
Set a value using dot notation |
has($key) |
Check if a key exists |
forget($key) |
Remove a key |
merge($data) |
Merge data into data |
replace($data) |
Replace all data |
clear() |
Clear all data |
isEmpty() |
Check if data is empty |
isNotEmpty() |
Check if data is not empty |
toArray() |
Get as array |
toCollection() |
Get as Laravel Collection |
toJson($options = 0) |
Get as JSON string |
count() |
Get number of items |
Static Methods
| Method | Description |
|---|---|
fromJson($json) |
Create from JSON string |
fromArray($array) |
Create from array |
fromCollection($collection) |
Create from collection |
Configuration
Publish the configuration file:
This will create config/json-mutator.php with the following options:
Testing
Run the tests:
Test Coverage
The package includes comprehensive test coverage for all functionality:
- ✅ JsonMutator Tests: All methods and edge cases
- ✅ JsonMutatorCast Tests: Traditional cast functionality
- ✅ JsonMutatorAttributeCast Tests: Laravel 11+ Attribute cast
- ✅ Integration Tests: Full Laravel integration
Continuous Integration
This package uses GitHub Actions for continuous integration:
- Multiple PHP versions: 8.2, 8.3
- Latest Laravel version: 12.x
- Code coverage: Uploaded to Codecov
- Automatic testing: On every push and pull request
Development
Local Development Setup
-
Clone the repository:
-
Install dependencies:
-
Run tests:
- Run tests with coverage:
Contributing
Please see CONTRIBUTING.md for details.
License
The MIT License (MIT). Please see License File for more information.
Credits
- Arayik Grigoryan
- All Contributors