wesselperik/nova-status-field

A Laravel Nova field for displaying statuses.

2.0.0 2022-04-05 22:42 UTC

This package is auto-updated.

Last update: 2022-05-05 22:49:41 UTC


README

Nova Status Field

Latest Version on Packagist Gitmoji

🚀 Compatible with Laravel Nova 4.0!

A Laravel Nova field for displaying a status icon, with optional tooltip and info text, on index and detail pages of your models. This package utilizes several icons from the Heroicons UI icon pack (from designer Steve Schroger), which is also used in Laravel Nova.

Installation

You can install the package using composer:

composer require wesselperik/nova-status-field

Next up, add the field to your desired Nova model. See the example below:

// for example, in app/Nova/Blog.php

use WesselPerik\StatusField\StatusField;

// ...

public function fields(Request $request) {
    return [
        // Use a single value for tooltips and info...
        StatusField::make('Published')
            ->values([
                'inactive'  => $this->published == 0,
                'pending'   => $this->pending == 1 && $this->published == 0,
                'active'    => $this->pending == 0 && $this->published == 1
            ])
            ->tooltip($this->status) // optional
            ->info("Blog status: ".$this->status) // optional
            ->exceptOnForms()

        // ...or change text based on the value
        StatusField::make('Published')
            ->values([
                'inactive'  => $this->published == 0,
                'pending'   => $this->pending == 1 && $this->published == 0,
                'active'    => $this->pending == 0 && $this->published == 1
            ])
            ->tooltip([
                'inactive'  => 'Not published',
                'pending'   => 'Pending publication',
                'active'    => 'Published'
            ])
            ->info([
                'inactive'  => 'This blog is not published yet.',
                'pending'   => 'This blog is pending publication.',
                'active'    => 'This blog is published on '.$this->published_at->format('d-m-Y').'.'
            ])
            ->exceptOnForms()
    ];
}

Available values (with matching icons) are:

  • inactive (cross)
  • active (checkmark)
  • pending (clock)
  • info (info icon)
  • warning (exclamation mark)
  • help (questionmark)
  • disabled (minus)

License

The MIT License (MIT). Please see the license file for more information.