thijssimonis/nova-list-card

在表格卡片中列出行。

1.1.1 2021-08-18 22:47 UTC

This package is auto-updated.

Last update: 2024-09-19 05:08:26 UTC


README

Latest Stable Version Total Downloads License

在表格卡片中列出行。例如,列出最新的5个用户。

screenshot01

安装

您可以在任何运行Laravel Nova的应用中安装此软件包

composer require thijssimonis/nova-list-card

使用方法

卡片

<?php

namespace App\Nova\Metrics;

use App\User;
use ThijsSimonis\NovaListCard\NovaListCard;

class LatestUsers extends NovaListCard
{
    public $width = '1/2';

    public function __construct()
    {
        parent::__construct();

        $this->rows(User::select(['id', 'name'])->orderBy('created_at', 'DESC')->limit(5)->get()->map(function ($row) {
            $row['view'] = config('nova.path') . '/resources/users/' . $row['id'];
            return $row;
        })));
    }

    public function uriKey(): string
    {
        return 'latest-users';
    }
}

内联

<?php

use App\User;
use ThijsSimonis\NovaListCard\NovaListCard;

class NovaServiceProvider extends NovaApplicationServiceProvider
{
    protected function cards(): array
    {
        return [
            (new NovaListCard())
                ->title(__('5 latest users'))
                ->rows(User::select('id', 'name')->orderBy('created_at', 'DESC')->limit(5)->get()),
        ];
    }
}

带有标题的内联

<?php

use App\User;
use ThijsSimonis\NovaListCard\NovaListCard;

class NovaServiceProvider extends NovaApplicationServiceProvider
{
    protected function cards(): array
    {
        return [
            (new NovaListCard())
                ->title(__('5 latest users'))
                ->heads([__('ID'), __('Name'))
                ->rows(User::select('id', 'name')->orderBy('created_at', 'DESC')->limit(5)->get()),
        ];
    }
}

变更日志

请参阅变更日志了解最近更改的详细信息。

贡献

请参阅贡献指南以获取详细信息。

鸣谢

许可证

MIT许可证(MIT)。请参阅许可证文件以获取更多信息。