PHPackages                             norman-huth/nova-default-fields - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. norman-huth/nova-default-fields

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

norman-huth/nova-default-fields
===============================

Standard fields for each resource

00

Since Dec 24Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Muetze42/nova-default-fields)[ Packagist](https://packagist.org/packages/norman-huth/nova-default-fields)[ RSS](/packages/norman-huth-nova-default-fields/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Nova Default Fields (Snipped - No Install)
==================================================

[](#laravel-nova-default-fields-snipped---no-install)

Standard fields for each resource.
No installation necessary.
Tested with Nova 4.

Instruction
-----------

[](#instruction)

Add following content to the Nova base resource (`app/Nova/Resources/Resource.php`):

```
     /**
     * Get the fields that are available for the given request.
     *
     * @param NovaRequest  $request
     * @return FieldCollection
     */
    public function availableFields(NovaRequest $request): FieldCollection
    {
        $method = $this->fieldsMethod($request);
        $fields = array_merge($this->{$method}($request), $this->defaultFields($request));

        return FieldCollection::make(array_values($this->filter($fields)));
    }

    /**
     * Get the fields that are available for the given request.
     *
     * @param NovaRequest $request
     * @param  array  $methods
     * @return FieldCollection
     */
    public function buildAvailableFields(NovaRequest $request, array $methods): FieldCollection
    {
        $fields = collect([
            method_exists($this, 'fields') ? array_merge($this->fields($request), $this->defaultFields($request)) : [],
        ]);

        collect($methods)
            ->filter(function ($method) {
                return $method != 'fields' && method_exists($this, $method);
            })->each(function ($method) use ($request, $fields) {
                $fields->push([$this->{$method}($request)]);
            });

        return FieldCollection::make(array_values($this->filter($fields->flatten()->all())));
    }

    /**
     * Default fields for every resource
     *
     * @param NovaRequest $request
     * @return array
     */
    protected function defaultFields(NovaRequest $request): array
    {
        return [];
    }
```

### Define Default Fields

[](#define-default-fields)

You can define the default fields in the `defaultFields` method

#### Example 1

[](#example-1)

```
    protected function defaultFields(NovaRequest $request): array
    {
        return [
            DateTime::make(__('Created at'), 'created_at')
                ->sortable()->filterable()->exceptOnForms(),
            DateTime::make(__('Updated at'), 'updated_at')
                ->sortable()->filterable()->exceptOnForms(),
        ];
    }
```

#### Example 2

[](#example-2)

With options `$showCreatedAtField`, `showCreatedAtField()`, `$showUpdatedAtField` &amp; `showUpdatedAtField()` and check if required colum exist `static::$model::CREATED_AT` &amp; `static::$model::UPDATED_AT`

```
    /**
     * Show in this resource the DateTime field `created_at`
     *
     * @var bool
     */
    public bool $showCreatedAtField = true;
    public function showCreatedAtField(NovaRequest $request): bool
    {
        return $this->showCreatedAtField;
    }

    /**
     * Show in this resource the DateTime field `updated_at`
     *
     * @var bool
     */
    public bool $showUpdatedAtField = true;
    public function showUpdatedAtField(NovaRequest $request): bool
    {
        return $this->showUpdatedAtField;
    }

    protected function defaultFields(NovaRequest $request): array
    {
        $fields = [];

        if ($this->showCreatedAtField($request) && static::$model::CREATED_AT) {
            $fields = array_merge($fields, [
                DateTime::make(__('Created at'), 'created_at')
                    ->sortable()->filterable()->exceptOnForms()
            ]);
        }

        if ($this->showUpdatedAtField($request) && static::$model::UPDATED_AT) {
            $fields = array_merge($fields, [
                DateTime::make(__('Updated at'), 'updated_at')
                    ->sortable()->filterable()->exceptOnForms()
            ]);
        }

        /*
         * For SoftDeletes
         * */
        if ($request->input('trashed')) {
            $fields = array_merge($fields, [
                DateTime::make(__('Deleted at'), 'deleted_at')
                    ->sortable()->filterable()->exceptOnForms()
            ]);
        }

        /*
         * For spatie/laravel-activitylog
         * */
        if (method_exists(static::$model, 'getLogName')) {
            $fields = array_merge($fields, [
                MorphMany::make(__('Activities'), 'activities', Activity::class)
            ]);
        }

        return $fields;
    }
```

---

[![More Laravel Nova Packages](https://raw.githubusercontent.com/Muetze42/asset-repo/main/svg/more-laravel-nova-packages.svg)](https://huth.it/nova-packages)

[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://vshymanskyy.github.io/StandWithUkraine/)[![Woman. Life. Freedom.](https://raw.githubusercontent.com/Muetze42/Muetze42/2033b219c6cce0cb656c34da5246434c27919bcd/files/iran-banner-big.svg)](https://linktr.ee/CurrentPetitionsFreeIran)

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity24

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2579233?v=4)[Muetze](/maintainers/Muetze)[@muetze](https://github.com/muetze)

---

Top Contributors

[![Muetze42](https://avatars.githubusercontent.com/u/26193232?v=4)](https://github.com/Muetze42 "Muetze42 (4 commits)")

---

Tags

laravellaravel-novanova-4

### Embed Badge

![Health badge](/badges/norman-huth-nova-default-fields/health.svg)

```
[![Health](https://phpackages.com/badges/norman-huth-nova-default-fields/health.svg)](https://phpackages.com/packages/norman-huth-nova-default-fields)
```

###  Alternatives

[graphp/graphviz

GraphViz graph drawing for the mathematical graph/network library GraPHP.

3302.3M53](/packages/graphp-graphviz)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
