area17/component-transformers
最新稳定版本:v0.2
Composer 安装命令:
composer require area17/component-transformers
包简介
Component transformers for Twill apps
README 文档
README
Design systems are made up of components designed to be used everywhere but often code used to parse data for the components is repeated during integration. The Component Transformers package allows you to create a transformer for each component and variation to transform the data coming from the application into a format the front end components will be able to consume.
It's designed to be used with Twill and works with both page and block data.
Publish config
php artisan vendor:publish --tag=component-transformers-config
Creating a Transformer
You can manually create a file in your app directory using the following as a base:
<?php namespace App\Transformers; use A17\ComponentTransformers\Base; class ComponentName extends Base { public function primary($data = null): array { return [ // 'title' => $data->title ?? null, ]; } }
or you can automatically create one with the built in command:
php artisan transformer:create
This will create a file like the one above in your app directory. If a file with the same name as the component name you entered, if will add a method to the end of that file using the variation name.
Using a transformer
In a block
$items = Transform::listing($block->getRelated('items'))->primary();
In a controller
use A17\ComponentTransformers\Transform; class MyController extends Controller { public function index() { $item = MyModel::first(); return [ 'hero' => Transform::hero($item)->primary(), 'listing' => Transform::listing($item)->primary(), ]; } }
统计信息
- 总下载量: 1.3k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2023-04-10