novius/laravel-json-casted
Cast JSON columns in Laravel models with per-key casting. Define sub-key casts via a method or dedicated cast class; values are exposed as a Fluent object with proper types (e.g., Carbon dates). Supports PHP 8.2+ and Laravel 10+.
{"metadata": {"published_at": "2023-01-01"}}) to native types (e.g., Carbon) for validation/processing.{"settings": {"is_active": "true"}}) to booleans/collections.Adopt When:
json_decode($model->extras)->date).Look Elsewhere If:
"This package automates the conversion of messy JSON data into clean, usable formats—like turning a string date into a Carbon object—without writing repetitive code. It’s a 10-minute setup that saves hours of debugging and maintenance, especially for APIs or admin tools where JSON fields are common. Think of it as ‘auto-formatting’ for your database JSON blobs."
ROI:
*"This solves the pain of manually casting nested JSON fields in Eloquent models. Instead of writing:
$model->extras = json_decode($model->extras, true);
$model->extras['date'] = Carbon::parse($model->extras['date']);
You define casts once (e.g., ['extras' => JsonCasted::class]), and Laravel handles the rest. It’s lightweight, integrates with IDE helpers, and works with Laravel’s existing casting ecosystem."*
Key Benefits:
laravel-ide-helper for autocompletion.How can I help you explore Laravel packages today?