think.studio/nova-has-many-on-index

A Laravel Nova field used to display a 'Has Many' relationship on the index screen.

1.1.0 2023-09-03 13:49 UTC

This package is auto-updated.

Last update: 2024-12-03 18:13:06 UTC


README

Packagist License Packagist Version Total Downloads Build Status Code Coverage Scrutinizer Code Quality

A Laravel Nova field used to display a 'Has Many' relationship on the index screen.
Very focused package for display quantity and list. May slow down the display of the index page

Installation

composer require think.studio/nova-has-many-on-index

Usage

\NovaHasManyIndex\NovaHasManyOnIndex::make(trans('cols-computed.subscriptions'), 'subscriptions_count')
        ->displayUsing(function ($val, $model) {
            return [
                'val'          => $val,
                'items'        => $model->subscriptions->map(function ($item) {
                    return [
                        'url'    => route('nova.pages.detail', [
                            'resource' => Contact::uriKey(),
                            'resourceId' => $item->getKey(),
                        ]),
                        'title' => "({$item->getKey()}) $item->name",
                        'icon' => [
                            'type' => 'trash',
                            'solid' => true,
                            'class' => 'text-red-500',
                        ],
                    ];
                })->all(),
            ];
        })
        ->sortable(),

Credits

  • Think Studio