itstructure/laravel-detail-view
最新稳定版本:1.0.6
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+
- php >= 7.1
- composer
Installation
General from remote packagist repository
Run the composer command:
composer require itstructure/laravel-detail-view "~1.0.6"
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-2025 Andrey Girnik girnikandrey@gmail.com.
Licensed under the MIT license. See LICENSE.txt for details.
统计信息
- 总下载量: 6.41k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-04-24
