dytechltd / custom-table
Nova自定义表格卡片。展示您最新的数据(订单、帖子、用户...)为卡片或您喜欢的数据。
v0.0.4
2020-11-18 14:39 UTC
Requires
- php: >=7.1.0
This package is auto-updated.
Last update: 2024-09-13 23:24:05 UTC
README
简单的Nova卡片表格
简单的卡片表格,包含您选择的数据。
它可以作为最新订单列表或最新帖子、用户等的有用工具。
安装
您可以通过composer将此包安装到使用Nova的Laravel应用中
composer require dytechltd/custom-table
您必须使用NovaServiceProvider注册卡片。
// in app/Providers/NovaServiceProvder.php // ... public function cards() { return [ // ... // all the parameters are required excelpt title new \Dytechltd\CustomTable\CustomTable( array $header, array $data, string $title ), ]; }
使用示例
// ... public function cards() { return [ // ... // all the parameters are required new \Dytechltd\CustomTable\CustomTable( [ new \Dytechltd\CustomTable\Table\Cell('Order Number'), (new \Dytechltd\CustomTable\Table\Cell('Price'))->class('text-right'), ], // header [ (new \Dytechltd\CustomTable\Table\Row( new \Dytechltd\CustomTable\Table\Cell('2018091001'), (new \Dytechltd\CustomTable\Table\Cell('20.50'))->class('text-right')->id('price-2') ))->viewLink('/resources/orders/1'), (new \Dytechltd\CustomTable\Table\Row( new \Dytechltd\CustomTable\Table\Cell('2018091002'), (new \Dytechltd\CustomTable\Table\Cell('201.25'))->class('text-right')->id('price-2') )), ], // data 'Orders' //title ), ]; }
或
// ... public function cards() { return [ // ... // all the parameters are required except title (new \Dytechltd\CustomTable\CustomTableCard) ->header([ new \Dytechltd\CustomTable\Table\Cell('Order Number'), (new \Dytechltd\CustomTable\Table\Cell('Price'))->class('text-right'), ]) ->data([ (new \Dytechltd\CustomTable\Table\Row( new \Dytechltd\CustomTable\Table\Cell('2018091001'), (new \Dytechltd\CustomTable\Table\Cell('20.50'))->class('text-right')->id('price-2') ))->viewLink('/resources/orders/1'), (new \Dytechltd\CustomTable\Table\Row( new \Dytechltd\CustomTable\Table\Cell('2018091002'), (new \Dytechltd\CustomTable\Table\Cell('201.25'))->class('text-right')->id('price-2') )), ]) ->title('Orders') ->refresh(5), // If you need refresh your card data (in seconds) ]; }
或
您可以在Nova/Cards目录中创建自己的类,该类将扩展 \Dytechltd\CustomTableCard\CustomTableCard
在这个独立的类中,您能够以优雅、干净的方式从模型中获取数据。
<?php namespace App\Nova\Cards; use App\Models\User; class UnverifiedUsers extends \Dytechltd\CustomTable\CustomTableCard { public function __construct() { $header = collect(['ID', 'NAME', 'EMAIL', 'PHONE NUMBER', 'INTRODUCER', 'VERIFIED', 'LAST LOGIN AT']); $this->title('Unverified Users'); $users = User::whereNull('email_verified_at') ->get(); $this->header($header->map(function ($value) { return new Cell($value); })->toArray()); $this->data(collect($users)->map(function ($user) { return (new Row( new Cell($user->id), new Cell($user->name), new Cell($user->email), new Cell($user->phone_number), new Cell($user->introducer ? $user->introducer->name : '--'), new Cell($user->email_verified_at), new Cell($user->last_login_at) ))->viewLink("resources/users/{$user->id}"); })->toArray()); } }
然后在NovaServiceProvider.php中注册您的自定义类
protected function cards() { return [ ...... new \App\Nova\Cards\UnverifiedUsers ]; }
注意:如果您没有指定视图,则显示图标将不可见。