techouse/total-records

此包已被废弃,不再维护。未建议替代包。

一个显示特定模型记录总数的Laravel Nova卡片。

v1.4.0 2022-02-13 20:27 UTC

This package is auto-updated.

Last update: 2022-07-26 10:12:17 UTC


README

Latest Version on Packagist Total Downloads Licence PHP version Codacy Badge GitHub stars

一个显示特定模型记录总数的Laravel Nova卡片。

当你只想显示某个模型数据库记录的总数。不多也不少。

Total Records

安装

您可以通过composer将此包安装到使用Nova的Laravel应用中

composer require techouse/total-records

使用方法

要将此卡片添加到仪表板,请打开App\Providers\NovaServiceProvider并将它添加到cards方法中,如下所示

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Gate;
use Laravel\Nova\{Nova, NovaApplicationServiceProvider};
use Techouse\TotalRecords\TotalRecords;

class NovaServiceProvider extends NovaApplicationServiceProvider
{
       /**
         * Get the cards that should be displayed on the Nova dashboard.
         *
         * @return array
         */
        protected function cards()
        {
            return [
                /**
                  * PARAMETERS:
                  *
                  * @param string             $model   required - the model you want to get the total count of
                  * @param string             $title   optional - the label you want to display in the Nova Card before the model count
                  * @param \DateTimeInterface $expires optional - the cache expiry time
                  */
                new TotalRecords(\App\User::class),                                            // minimum required parameters
                new TotalRecords(\App\Event::class, __('Total events')),                       // with custom label
                new TotalRecords(\App\Contact::class, __('Total contacts'), now()->addHour()), // cached for 1 hour
            ];
        }
}