Laravel Community Tools by Tighten
Laravel Nova icon Nova Packages
I

Inline Badge Field

Readme

Nova Inline Badge Field

Latest Version on Packagist Total Downloads

This Laravel Nova package adds an inline badge field to Nova's arsenal of fields.

Requirements

  • php: >=8.0
  • laravel/nova: ^5.0

Features

A Select field on Form views that renders as a colored badge on Index and Detail views. Clicking the badge opens a native <select>; picking a value sends a Nova update request for the resource and re-colors the badge inline — no need to open the edit form.

Demo

Installation

Install the package in to a Laravel app that uses Nova via composer:

composer require versioon/nova-inline-badge-field

Usage

General

The field extends Nova's Select field, so options() defines the dropdown choices used on both the form and the inline editor. map() maps each value to a badge type (success, info, danger, warning, or a custom type registered via types()).

use Versioon\NovaInlineBadgeField\InlineBadge;

public function fields(Request $request) {
    InlineBadge::make('Status')
        ->options([
            'draft' => 'Draft',
            'published' => 'Published',
            'archived' => 'Archived',
        ])
        ->map([
            'draft' => 'warning',
            'published' => 'success',
            'archived' => 'danger',
        ]),
}

Customizing badges

The following Badge-style helpers are available in addition to everything inherited from Select:

InlineBadge::make('Status')
    ->options([...])

    // Map field values to built-in or custom badge types.
    ->map(['draft' => 'warning', 'published' => 'published'])

    // Register custom badge types and their CSS classes.
    ->types([
        'published' => 'bg-green-100 text-green-600 dark:bg-green-500 dark:text-green-900',
    ])

    // Override the label shown on the badge per value...
    ->labels(['published' => 'Live'])
    // ...or resolve it with a callback.
    ->label(fn ($value) => ucfirst($value))

    // Show an icon on the badge (defaults provided for the built-in types).
    ->withIcons()
    ->icons(['published' => 'check-circle']),

If a value isn't present in map()/types(), the badge renders without a color class. Labels fall back to the matching options() label, then to the raw value.

Credits

License

Nova Inline Badge Field is open-sourced software licensed under the MIT license.

Screenshots

Back to Top
Added 1 hour ago

This package is listed on the Packagist API, but has no stable tags.

Please note that the Packagist cache is pretty long, so some times you just need to check back in an hour.

Favorites

0 users favorited

Rating

N/A
(out of 5)
★★★★★
★★★★
★★★
★★
0 ratings

Author

Brought to you by Tighten

Issues/Feature Requests Stats Package Ideas