itstructure/laravel-detail-view
Composer 安装命令:
composer require itstructure/laravel-detail-view
包简介
Detail view table for laravel framework
README 文档
README
Introduction
This package is to displaying the model data in a Detail table.
Requirements
- laravel 5.5+ | 6+ | 7+ | 8+ | 9+ | 10+ | 11+ | 12+ | 13+
- php >= 7.1
- composer
Installation
General from remote packagist repository
Run the composer command:
composer require itstructure/laravel-detail-view "~1.0.8"
If you are testing this package from a local server directory
In application composer.json file set the repository, as in example:
"repositories": [ { "type": "path", "url": "../laravel-detail-view", "options": { "symlink": true } } ],
Here,
../laravel-detail-view - directory path, which has the same directory level as application and contains Detail View package.
Then run command:
composer require itstructure/laravel-detail-view:dev-main --prefer-source
Publish files (Not necessary)
-
To publish views run command:
php artisan detail_view:publish --only=viewsIt stores view files to
resources/views/vendor/detail_viewfolder. -
To publish translations run command:
php artisan detail_view:publish --only=langIt stores translation files to
resources/lang/vendor/detail_viewfolder. -
To publish all parts run command without
onlyargument:php artisan detail_view:publishElse you can use
--forceargument to rewrite already published files.
Else you can use --force argument to rewrite already published file.
Usage
View template part
Use @detailView() directive with config array in a blade view template.
Simple quick usage
You can simply set rows to display as string format in rowFields array.
Note: $model must be instance of Illuminate\Database\Eloquent\Model.
@php $detailData = [ 'model' => $model, 'title' => 'Detail table', 'rowFields' => [ 'id', 'active', 'icon', 'created_at' ] ]; @endphp
@detailView($detailData)
Alternative variant without a blade directive:
{!! detail_view([
'model' => $model,
'title' => 'Detail table',
'rowFields' => [
'id',
'active',
'icon',
'created_at'
]
]) !!}
Setting custom options
Rows
Simple example:
@detailView([ 'model' => $model, 'rowFields' => [ [ 'label' => 'First Name', // Row label. 'attribute' => 'first_name', // Attribute, by which the row data will be taken from a model. ], [ 'label' => 'Last Name', 'value' => function ($model) { return $model->last_name; } ], ] ])
Formatters
There are the next formatter keys:
- html - is for passing a row content with html tags.
- image - is for inserting a row data in to
srcattribute of<img>tag. - text - applies
strip_tags()for a row data. - url - is for inserting a row data in to
hrefattribute of<a>tag.
For that keys there are the next formatters:
HtmlFormatterImageFormatterTextFormatterUrlFormatter
Also you can set formatter with some addition options. See the next simple example:
@detailView([ 'model' => $model, 'rowFields' => [ [ 'attribute' => 'url', 'format' => [ 'class' => Itstructure\DetailView\Formatters\UrlFormatter::class, 'title' => 'Source', 'htmlAttributes' => [ 'target' => '_blank' ] ] ], [ 'attribute' => 'content', 'format' => 'html' ] ] ])
Table heads
To set column titles, you can set captionColumnConfig and valueColumnConfig as in example:
@detailView([ 'model' => $model, 'captionColumnConfig' => [ 'label' => 'Custom title column', 'htmlAttributes' => [ 'class' => 'th-title-class' ] ], 'valueColumnConfig' => [ 'label' => 'Custom value column', 'htmlAttributes' => [ 'class' => 'th-value-class' ] ], 'rowFields' => [ [ 'attribute' => 'content', ] ] ])
To hide all table row with head titles:
@detailView([ 'model' => $model, 'showHead' => false, 'rowFields' => [ [ 'attribute' => 'content', ] ] ])
Complex extended example
@php $detailData = [ 'model' => $model, 'title' => 'Detail title', // It can be empty '' 'htmlAttributes' => [ 'class' => 'table table-bordered table-striped' ], 'captionColumnConfig' => [ 'label' => 'Custom title column', 'htmlAttributes' => [ 'class' => 'th-title-class' ] ], 'valueColumnConfig' => [ 'label' => 'Custom value column', 'htmlAttributes' => [ 'class' => 'th-value-class' ] ], 'rowFields' => [ [ 'attribute' => 'id', // REQUIRED if value is not defined. Attribute name to get row model data. 'label' => 'ID', // Row label. 'htmlAttributes' => [ 'class' => 'tr-class' ] ], [ 'label' => 'Active', // Row label. 'value' => function ($model) { // You can set 'value' as a callback function to get a row data value dynamically. return '<span class="icon fas '.($model->active == 1 ? 'fa-check' : 'fa-times').'"></span>'; }, 'format' => 'html', // To render row content without lossless of html tags, set 'html' formatter. ], [ 'label' => 'Url link', // Row label. 'attribute' => 'url', // REQUIRED if value is not defined. Attribute name to get row model data. 'format' => [ // Set special formatter. $model->{$this->attribute} will be inserted in to 'href' attribute of <a> tag. 'class' => Itstructure\DetailView\Formatters\UrlFormatter::class, // REQUIRED. For this case it is necessary to set 'class'. 'title' => 'Source', // title between a tags. 'htmlAttributes' => [ // Html attributes for <a> tag. 'target' => '_blank' ] ] ], [ 'label' => 'Icon', // Row label. 'value' => function ($model) { // You can set 'value' as a callback function to get a row data value dynamically. return $model->icon; }, 'format' => [ // Set special formatter. If $model->icon value is a url to image, it will be inserted in to 'src' attribute of <img> tag. 'class' => Itstructure\DetailView\Formatters\ImageFormatter::class, // REQUIRED. For this case it is necessary to set 'class'. 'htmlAttributes' => [ // Html attributes for <img> tag. 'width' => '100' ] ] ], 'created_at', // Simple row setting by string. ] ]; @endphp
@detailView($detailData)
License
Copyright © 2021-2026 Andrey Girnik girnikandrey@gmail.com.
Licensed under the MIT license. See LICENSE.txt for details.
itstructure/laravel-detail-view 适用场景与选型建议
itstructure/laravel-detail-view 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.78k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 04 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「view」 「laravel」 「table」 「detail」 「detailview」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 itstructure/laravel-detail-view 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 itstructure/laravel-detail-view 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 itstructure/laravel-detail-view 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Plug-ins for DataTables
A component that allows creating responsive HTML tables or lists from data object
Adjacency List’ed Closure Table database design pattern implementation for Laravel. Includes restore of tree
Illuminate View for Morningmedley.
Blade template for Kirby
统计信息
- 总下载量: 6.78k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-04-24
