whitespacecode/nova-table-card
Composer 安装命令:
composer require whitespacecode/nova-table-card
包简介
Nova table card. Show your latest data (orders, posts,...) as card or data you prefer.
README 文档
README
Simple Nova Card for Displaying Tables
NOTE: This has been forked from m-a-k-o/nova-custom-table-card, see issue #8
Simple card table with data of you choice.
It can be useful as latest order list or latest posts, ...
Requirements
php: >=8.1laravel/nova: ^4.0
Installation
You can install the package in to a Laravel app that uses Nova via composer:
composer require whitespacecode/nova-table-card
You must register the card with NovaServiceProvider.
// in app/Providers/NovaServiceProvder.php // ... public function cards() { return [ // ... // all the parameters are required excelpt title new \Whitespacecode\TableCard\TableCard( array $header, array $data, string $title, array $viewAll ), ]; }
Example of use:
use Whitespacecode\TableCard\TableCard; use Whitespacecode\TableCard\Table\Cell; use Whitespacecode\TableCard\Table\Row; // ... public function cards() { return [ // ... // all the parameters are required except title and/or viewLink (new TableCard) ->header([ Cell::make('Order Number'), // Set sortable to true in a header Cell to allow its column's sorting (Cell::make('Price'))->sortable(true)->class('text-right'), ]) ->data([ (Row::make( Cell::make('2018091001'), (Cell::make('20.50'))->class('text-right')->id('price-2') ))->viewLink('/resources/orders/1'), //Add viewLink to show clickable eye (Row::make( Cell::make('2018091002'), (Cell::make('201.25'))->class('text-right')->id('price-2') )), ]) ->title('Orders') ->viewAll(['label' => 'View All', 'link' => '/resources/orders']), ]; }
or:
You can create your own class which will extend \Whitespacecode\TableCard\TableCard in Nova/Cards directory on example.
In this separate class you are able to fetch data from models in nice clean way.
<?php namespace App\Nova\Cards; use Whitespacecode\TableCard\TableCard; use Whitespacecode\TableCard\Table\Cell; use Whitespacecode\TableCard\Table\Row; use App\Models\Order; class LatestOrders extends TableCard { public function __construct() { $header = collect(['Date', 'Order Number', 'Status', 'Price', 'Name']); $this->title('Latest Orders'); $this->viewAll([ 'label' => 'View All', //Default value `View All` 'link' => '/resources/orders', //Required field 'position' => 'bottom' //Default value `top` 'style' => 'button' //Default value `link` ]); // $orders = Order::take(10)->latest->get(); // Data from you model $orders = collect([ ['date' => '2018-12-01', 'order_number' => '2018120101', 'status' => 'Ordered', 'price' => '20.55', 'name' => 'John Doe'], ['date' => '2018-12-01', 'order_number' => '2018120101', 'status' => 'Ordered', 'price' => '20.55', 'name' => 'John Doe'], ['date' => '2018-12-01', 'order_number' => '2018120101', 'status' => 'Ordered', 'price' => '20.55', 'name' => 'John Doe'], ['date' => '2018-12-01', 'order_number' => '2018120101', 'status' => 'Ordered', 'price' => '20.55', 'name' => 'John Doe'], ['date' => '2018-12-01', 'order_number' => '2018120101', 'status' => 'Ordered', 'price' => '20.55', 'name' => 'John Doe'], ['date' => '2018-12-01', 'order_number' => '2018120101', 'status' => 'Ordered', 'price' => '20.55', 'name' => 'John Doe'], ]); $this->header($header->map(function($value) { // Make the Status column sortable return ($value === 'Status') ? (Cell::make($value))->sortable(true) : Cell::make($value); })->toArray()); $this->data($orders->map(function($order) { return Row::make( Cell::make($order['date']), Cell::make($order['order_number']), // Instead of alphabetically ordering the status, set a sortableData value for better representation (Cell::make($order['status'])->sortableData($this->getStatusSortableData($order['status']))), Cell::make($order['price']), Cell::make($order['name']) ); })->toArray()); //Possible style configuration // $this->style = 'tight'; // $this->width = 'full'; } private function getStatusSortableData (string $status) : int { switch ($status) { case 'Ordered': return 1; default: return 0. } } }
Then simply include your custom class like a normal card within your resource
use App\Nova\Cards\LatestOrders; protected function cards() { return [ ...... new LatestOrders, ]; }
Note:
If you don't specify viewLink() on a row Row::make()->viewLink(), show icon will not be visible.
Additional Fields in viewAll
You can also show a viewAll on the table with $this->viewAll()
- label (optional): By default, it is set to 'View All'.
- position (optional): By default, it is set to 'top'. You can change it to 'bottom' if needed.
- style (optional): DThe default style is a 'link'. Alternatively, you can set it to 'button' for a button-style appearance.
$this->viewAll([ 'label' => '__('Latest Orders')', 'link' => '/resources/orders', //URL to navigate when the link is clicked 'position' => 'bottom', //(Possible values `top` - `bottom`) 'style' => 'button', //(Possible values `link` - `button`) ]);
Table Style Customization
To show more data on your table, you can use the "tight" table style option designed to increase the visual density of your table rows.
use Whitespacecode\TableCard\TableCard; protected function cards() { return [ ... TableCard::make( ... )->style('tight'), ]; }
Or override the $style property on your custom class:
$this->style = 'tight';
Change the width of the table cards (1/3, 1/2, or full)
By default, it is set to 'full'
$this->width = '1/3';
Using the pagination
The pagination accepts a default Illuminate\Pagination\LengthAwarePaginator
When getting your data just use the default ->paginate() and pass your data to the paginator.
Everything else stays the same.
class LatestOrders extends TableCard { public function __construct() { $orders = Orders::paginate(5); //You want to start by showing the latest result? Get them by latest //$orders = Orders::latest()->paginate(5); $this->paginator($orders); } }
Multiple TableCards with pagination per page
Sometimes you may need to render multiple TableCard instances with pagination on the same page or dashboard. However, those paginator instances use the page query string to track the current page and the paginators will conflict.
To resolve this, you can customize the query string the name of the query string used by each paginator by passing a third argument to the paginate method.
Official documentation in the Laravel Pagination Docs.
// Set a unique query key for this paginator $this->queryKey('orders'); // Pass the query key to paginate $orders = Orders::paginate(5, ['*'], 'orders');
whitespacecode/nova-table-card 适用场景与选型建议
whitespacecode/nova-table-card 是一款 基于 Vue 开发的 Composer 扩展包,目前已累计 116.56k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2023 年 05 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「nova」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 whitespacecode/nova-table-card 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 whitespacecode/nova-table-card 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 whitespacecode/nova-table-card 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova card that shows you your system information.
A Laravel Nova card.
A Laravel Nova package for publishable fields
A Laravel Nova package for translatable fields
A Laravel Nova Image field. you can paste or drag or chose an image
A Laravel Nova Mail testing tool.
统计信息
- 总下载量: 116.56k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-26

