PHPackages                             novius/laravel-json-casted - 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. novius/laravel-json-casted

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

novius/laravel-json-casted
==========================

A package to cast json fields, each sub-keys is castable

1.3.0(1mo ago)04.7k↓27%3AGPL-3.0-or-laterPHPPHP &gt;=8.2CI passing

Since Dec 12Pushed 1mo ago2 watchersCompare

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

READMEChangelog (5)Dependencies (13)Versions (6)Used By (3)

Laravel Json Casted
===================

[](#laravel-json-casted)

[![Novius CI](https://github.com/novius/laravel-json-casted/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/novius/laravel-json-casted/actions/workflows/main.yml)[![Packagist Release](https://camo.githubusercontent.com/c5511ec0086b11dec89625c2532ce21857eca3daa308dfbb01d0c4fc163a2eab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6f766975732f6c61726176656c2d6a736f6e2d6361737465642e7376673f6d61784167653d31383030267374796c653d666c61742d737175617265)](https://packagist.org/packages/novius/laravel-json-casted)[![License: AGPL v3](https://camo.githubusercontent.com/c61341f63648cdd5aba4f7a073b513106a63778c27b15f96c56157642bc943b4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4147504c25323076332d626c75652e737667)](http://www.gnu.org/licenses/agpl-3.0)

Introduction
------------

[](#introduction)

A package to cast json fields, each sub-keys is castable

Requirements
------------

[](#requirements)

- PHP &gt;= 8.2
- Laravel 10.0

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

[](#installation)

You can install the package via composer:

```
composer require novius/laravel-json-casted
```

If you use [laravel-ide-helper](https://github.com/barryvdh/laravel-ide-helper/tree/master?tab=readme-ov-file#automatic-phpdocs-for-models), add `ModelHasJsonWithCastsHook` in its configuration file :

```
    'model_hooks' => [
        // ...
        \Novius\LaravelJsonCasted\Hooks\ModelHasJsonWithCastsHook::class,
    ],
```

Usage
-----

[](#usage)

### Define casts by a method

[](#define-casts-by-a-method)

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Novius\LaravelJsonCasted\Services\JsonCasted;

class Post extends Model {

    protected $casts = [
        'extras' => JsonCasted::class.':getExtrasCasts',
    ];

    public function getExtrasCasts(): array
    {
        return [
            'date' => 'date:Y-m-d',
        ];
    }
}
```

### Define casts by a class

[](#define-casts-by-a-class)

```
namespace App\Casts;

use Novius\LaravelJsonCasted\Services\JsonCasted;

class Extras extends JsonCasted {

    protected static array $casts = [
        'date' => 'date:Y-m-d',
    ];
}
```

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Casts\Extras;

class Post extends Model {

    protected $casts = [
        'extras' => Extras::class,
    ];
}
```

### Use casted field

[](#use-casted-field)

```
    $model = Post::first();
    // $model->extras is now a Fluent instance
    // $model->extras->date is a now Carbon class
    $model->extras->date->lt(now());
```

CS Fixer
--------

[](#cs-fixer)

Lint your code with Laravel Pint using:

```
composer run cs-fix
```

Licence
-------

[](#licence)

This package is under [GNU Affero General Public License v3](http://www.gnu.org/licenses/agpl-3.0.html) or (at your option) any later version.

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance90

Actively maintained with recent releases

Popularity23

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Every ~117 days

Total

5

Last Release

53d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/341860?v=4)[Novius](/maintainers/novius)[@novius](https://github.com/novius)

---

Top Contributors

[![felixgilles](https://avatars.githubusercontent.com/u/900854?v=4)](https://github.com/felixgilles "felixgilles (14 commits)")

---

Tags

jsonlaraveleloquentcast

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11120.2M21](/packages/anourvalar-eloquent-serialize)[waad/laravel-model-metadata

A robust Laravel package for handling metadata with JSON casting, custom relation names, and advanced querying capabilities.

823.1k](/packages/waad-laravel-model-metadata)[io238/laravel-iso-countries

Ready-to-use Laravel models and relations for country (ISO 3166), language (ISO 639-1), and currency (ISO 4217) information with multi-language support.

5462.3k](/packages/io238-laravel-iso-countries)[cviebrock/eloquent-typecast

Trait for Eloquent models to force type-casting on retrieved values

2468.0k](/packages/cviebrock-eloquent-typecast)[stayallive/laravel-eloquent-observable

Register Eloquent model event listeners just-in-time directly from the model.

2928.9k7](/packages/stayallive-laravel-eloquent-observable)[hnhdigital-os/laravel-model-json

Provides JSON column support for for Laravel's Eloquent Model.

351.8k](/packages/hnhdigital-os-laravel-model-json)

PHPackages © 2026

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