定制 flashport/laravel-json-marshaller 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

flashport/laravel-json-marshaller

Composer 安装命令:

composer require flashport/laravel-json-marshaller

包简介

A laravel wrapper for the lib flashport/json-marshaller

README 文档

README

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',
];

统计信息

  • 总下载量: 1.24k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固