wongyip/laravel-renderable 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

wongyip/laravel-renderable

Composer 安装命令:

composer require wongyip/laravel-renderable

包简介

Render Eloquent model with ease.

README 文档

README

Present an Eloquent model or an associative array in HTML table view.

Installation

Install as a package to a Laravel project

composer require wongyip/laravel-rendetable

Usage

use Wongyip\Laravel\Renderable\Renderable;

// Attributes to be rendered, can be an Eloquent model.
$user = [
    'id' => 1999,
    'surname' => 'SOME',
    'last_name' => 'Body',
    'roles' => ['Operator', 'Editor', 'Supervisor'],
    'gender' => 'Male',
    'birthday' => '29th Feb',
    'active' => false
];

// Render all attributes except 'gender' and 'birthday'.
$included = true;
$excluded = ['gender', 'birthday'];

// Custom Labels
$labels = [
    'surname' => 'First Name',
    'active' => 'Status'
];

// Make
$r = Renderable::table($user, $included, $excluded);

// Render as <ul>, expected array value.
$r->typeUL('roles');

// Print 'Active' and 'Blocked' when attribute 'active' is TRUE and FALSE respectively.
$r->typeBool('active', 'Active', 'Blocked');

// Overwrite auto-generated labels.
$r->labels($labels);
    
// To HTML.
echo $r->render();

Output

<div id="renderable-12345678-container" class="renderable-container">
    <table id="renderable-12345678" class="table table-bordered table-strip renderable-table">
        <thead class="thead-light">
            <tr>
                <th class="renderable-field-header">Field</th>
                <th class="renderable-value-header">Value</th>
            </tr>
        </thead>
        <tbody class="renderable-body">
            <tr class="field-id">
                <th class="renderable-label">ID</th>
                <td class="renderable-value">1999</td>
            </tr>
            <tr class="field-surname">
                <th class="renderable-label">First Name</th>
                <td class="renderable-value">SOME</td>
            </tr>
            <tr class="field-last_name">
                <th class="renderable-label">Last Name</th>
                <td class="renderable-value">Body</td>
            </tr>
            <tr class="field-roles">
                <th class="renderable-label">Roles</th>
                <td class="renderable-value">
                    <ul>
                        <li>Operator</li>
                        <li>Editor</li>
                        <li>Supervisor</li>
                    </ul>
                </td>
            </tr>
            <tr class="field-active">
                <th class="renderable-label">Status</th>
                <td class="renderable-value">Blocked</td>
            </tr>
        </tbody>
    </table>
</div>

Output Explained

  • The main output is a <table> tag wrapped in a container <div> tag.
  • The Renderable object generates its own Renderable.id randomly on instantiate (12345678), which is changeable with the Renderable.id() method.
  • The main tag will have an id attribute derived from the Renderable.id, prefixed with renderable- by default, configurable via /config/renderable.php) and changeable on run-time by updating the Renderable.options.idPrefix property.
  • The container tag's ID is further suffixed with -containter by default, configurable via /config/renderable.php) and changeable on run-time by updating the Renderable.options.containerIdSuffix property.
  • Field labels and values are rendered base on the setup.

Notes

  • Output is formatted with HTML Beautify.
  • Output is sanitized with HTML Purifier.
  • The Renderable object is designed to render once only, use clone keyword to create multiple Renderable objects may end up fall into the variable referencing nightmare, do Deep Copy if multiple instance is really needed.

wongyip/laravel-renderable 适用场景与选型建议

wongyip/laravel-renderable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.74k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 12 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 wongyip/laravel-renderable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 wongyip/laravel-renderable 我们能提供哪些服务?
定制开发 / 二次开发

基于 wongyip/laravel-renderable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2021-12-06