Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Nova Toggle Laravel Package

almirhodzic/nova-toggle

almirhodzic/nova-toggle is a Laravel Nova field that adds a clean toggle switch for boolean attributes, letting you flip values directly from the resource index or detail view. Ideal for managing active/inactive or yes/no flags without leaving the resource list.

View on GitHub
Deep Wiki
Context7

Getting Started

Install or upgrade with Composer:

composer require almirhodzic/nova-toggle-5
# or, for existing installs
composer update almirhodzic/nova-toggle-5

This package provides an inline toggle endpoint/field for Laravel Nova 5 boolean attributes. Start by adding the package’s toggle field to a Nova resource for a boolean column, for example an active or published flag. Then confirm two things before relying on it:

  1. The attribute is included in the package’s toggleable-attribute whitelist.
  2. The resource’s policy/authorization allows the toggle action.

The first practical use case is an index-table toggle: let admins flip a boolean directly from a Nova resource index or lens without opening the detail page. If your resource uses SoftDeletes, v1.3.1 is the first release where toggling works correctly from “With Trashed” views and lenses that surface trashed rows.

Implementation Patterns

Inline boolean toggles in Nova resources. Add the package field to resources where a boolean represents a simple state change: active/inactive, featured/unfeatured, published/unpublished. This is best for low-risk flags that do not require additional form input or validation.

Whitelist only intentional attributes. The package enforces a toggleable-attribute whitelist. Treat that list as a security boundary: only expose columns that are safe to flip from an index view. Avoid wildcard or broad whitelists.

Authorize through policies/gates. The toggle endpoint applies authorization checks before changing the record. Implement a policy method or gate for the toggle action, and remember that the check applies to trashed records as well in v1.3.1.

Soft-delete-aware lenses and “With Trashed” views. If a lens or resource index includes trashed rows via withTrashed(), the package now resolves the record with withTrashed() when the Nova resource uses soft deletes. This means toggles from those views should work without custom route binding or manual lookup logic.

Use model events/observers for side effects. The toggle endpoint updates the attribute directly. If a toggle should send notifications, write audit logs, or invalidate caches, attach that behavior to model events or observers rather than duplicating endpoint logic.

Pair with Nova actions for complex transitions. Use the toggle for simple state flips. If changing the flag requires confirmation, validation, a reason, or a multi-step workflow, use a Nova action or detail form instead.

Gotchas and Tips

  • v1.3.1 is a drop-in patch. No breaking changes, migrations, or config changes are noted. Upgrade if you use “With Trashed” views or lenses that show soft-deleted records—prior versions returned a 404 from the toggle endpoint for those rows.
  • Authorization still applies to trashed records. Do not assume that a trashed row bypasses policy checks. If a toggle fails on a trashed record, verify both the policy and the whitelist.
  • A silent or rejected toggle usually means whitelist or policy. If the UI does not change the value, check that the attribute is explicitly toggleable and that the current user passes the toggle authorization check.
  • 404 debugging before v1.3.1. If you are on an older version and see 404s when toggling trashed rows, the fix is the withTrashed() lookup added in v1.3.1. Upgrade first before writing custom route-binding workarounds.
  • Custom global scopes can still interfere. The package applies withTrashed() for soft-delete resources, but custom global scopes or custom route model binding may still affect record resolution. Test toggles from the exact lens/index view your users rely on.
  • Keep the whitelist narrow. The convenience of inline toggling makes it tempting to expose many boolean columns. Restrict it to flags that are safe to change without a full form submission.
  • Extension points are model-level, not endpoint-level. Prefer observers, policies, and the package whitelist over overriding the toggle endpoint. This keeps upgrades to patch releases straightforward.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode
jjsquady/round-robin