New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

flashport/laravel-json-marshaller

A laravel wrapper for the lib flashport/json-marshaller
1,620 1
Install
composer require flashport/laravel-json-marshaller
Latest Version:v0.12.5
PHP:>=8.2
Laravel:12
Older releases:10 · 11
License:MIT
Last Updated:Mar 13, 2025
Links: GitHub  ·  Packagist
Maintainer: lscarpi

Laravel Json Marshaller

A laravel wrapper for the json-marshaller lib.

Installation:

    composer require flashport/laravel-json-marshaller

Usage:

There are two main ways of using this lib, it is possible to use existing target cast objects without modifying them, modifying only the model which performs the cast.

Option 1: Directly on the model

On the $casts array, specify the JsonMarshallable::class and the target class after :. This will ensure the target class gets passed as an argument to the Marshaller.

/**
 * The attributes that should be cast.
 *
 * @var array<string, string>
 */
protected $casts = [
    'metadata'      => JsonMarshallable::class . ":" . Metadata::class,
    'customFields'  => JsonMarshallable::class . ":" . CustomField::class,
    'active'        => 'bool',
];

Option 2: On the target classes

Target class:

Make sure to extend the AsJsonMarshallable class on your target classes.


use LaravelJsonMarshaller\Castables\AsJsonMarshallable;

class CustomField extends AsJsonMarshallable
{
    //...
}
Model:

On the model, specify only the target class name you want to cast into.

/**
 * The attributes that should be cast.
 *
 * @var array<string, string>
 */
protected $casts = [
    'metadata'      => Metadata::class,
    'customFields'  => CustomField::class,
    'active'        => 'bool',
];

Related Packages

inerciacreativa/json

PHP class for working with JSON objects

5 0
mortenscheel/tracer

A PHP library for advanced stack trace handling and debugging.

13,486 0
mortenscheel/laravel-query-recorder

A package to record and analyze database queries in Laravel applications.

13,283 1
joshcirre/inertiakit

File-based Inertia routing, simplified server controllers + typed models & props

10 5

Version History

Version Released PHP Laravel License
v0.12.5 >=8.2 ^12.0 MIT
v0.12.4 >=8.2 ^11.0 MIT
v0.12.3 >=8.2 ^11.0 MIT
v0.12.2 >=8.2 ^11.0 MIT
v0.12.1 >=8.2 ^11.0 MIT