定制 konsulting/fractal-helpers 二次开发

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

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

konsulting/fractal-helpers

Composer 安装命令:

composer require konsulting/fractal-helpers

包简介

README 文档

README

A small extension for Fractal that makes it easy to include relationships on a resource. Designed for use with Laravel/Eloquent, but it will work with any model or resource that expresses the same interface for retrieving relationships.

Installation

composer require konsulting/fractal-helpers

Usage

To make use of this package, in your transformers extend Konsulting\FractalHelpers\TransformerAbstract rather than the base Fractal transformer.

When building up APIs with Fractal I found myself repeating the same code to include relations on my Eloquent models:

// BookTransformer.php

protected $availableIncludes = [
    'author',
    'characters'
];

public function includeAuthor(Book $book) {
     return $this->item($book->author, new AuthorTransformer);
}

public function includeCharacters(Book $book) {
    return $this->collection($book->characters, new CharacterTransformer);
}

With the included TransformerAbstract class, you can express the above code more succinctly as:

// BookTransformer.php

protected $itemIncludes = [
    'author' => AuthorTransformer::class,
];

protected $collectionIncludes = [
    'characters' => CharacterTransformer::class,
];

Null relationships

If a relationship returns null, it will automatically be converted to a League\Fractal\Resource\NullResource object rather than passing to the associated transformer for that relationship. This means it's not necessary to check for null within each transformer.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-05-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固