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 Switch Laravel Package

brand3000/nova-toggle-switch

View on GitHub
Deep Wiki
Context7

Getting Started

Install via Composer, then register the field in a Nova resource. Nova field packages are not auto-discovered for UI compilation in older Nova versions, so check the package README for whether a nova:publish step or manual npm build is required.

composer require brand3000/nova-toggle-switch

Look first at:

  1. composer.json — the extra.laravel.providers block (if any) and the Nova version constraint under require. This is your fastest signal on whether it will even boot on your Nova install.
  2. src/ — the field class extends Laravel\Nova\Fields\Boolean (typical for toggle packages), which tells you every inherited method (trueValue, falseValue, nullable, rules, dependsOn) is available.
  3. resources/js/ — the Vue component. A tiny ToggleSwitch.vue that wraps a checkbox is the normal shape; if it's larger than that, expect opinionated styling you may need to override.

First use case — replace a Boolean field on a resource form:

use Brand3000\NovaToggleSwitch\ToggleSwitch;

public function fields(NovaRequest $request)
{
    return [
        ToggleSwitch::make('Active', 'is_active')
            ->trueValue(1)
            ->falseValue(0),
    ];
}

Confirm the exact class name and namespace from src/ before trusting this snippet — the leaf class is often named slightly differently than the package (ToggleSwitch vs NovaToggleSwitch).

Implementation Patterns

Basic boolean flag. The canonical use is a single boolean/tinyint column. Match trueValue/falseValue to the column type; don't let the field write true into a tinyint(1) that your app reads as 1.

ToggleSwitch::make('Published', 'is_published')
    ->trueValue(true)
    ->falseValue(false)
    ->rules('required', 'boolean')

Labels instead of raw booleans. Toggle UIs benefit from human labels. Most Nova boolean-derived fields accept a display map via ->trueValue() / ->falseValue() combined with ->displayUsing():

ToggleSwitch::make('Status', 'is_enabled')
    ->displayUsing(fn ($value) => $value ? 'Enabled' : 'Disabled')

Index and detail views. A toggle on the index table is read-only unless the package implements inline updates (most don't). Keep ->hideFromIndex() on noisy toggles and let a filter do the work:

ToggleSwitch::make('Active', 'is_active')
    ->hideFromIndex()
    ->filterable()

Conditional visibility in forms. Because the field is a Boolean subclass, dependsOn works:

Text::make('Expiry Reason')
    ->dependsOn('is_active', function ($field, $request, $formData) {
        return $formData->is_active === false;
    }),

Bulk / inline toggling. For day-to-day admin work, expose an action rather than forcing a form round-trip:

(new ToggleActive)->standalone()

where the action flips the column with $models->each->update(['is_active' => true]). This is usually more valuable than the field's rendered switch.

Filters. Pair the toggle with a BooleanFilter so a "Active only" tab exists in the index. The field package rarely ships one; write your own — it is three lines of apply().

Gotchas and Tips

Version drift is the real risk here. With ~10 stars and a low maintenance score, the package was almost certainly built against one Nova major (likely Nova 3 or 4). Nova 4/5 rewrote the frontend toolchain, Vue 3 migration, and Tailwind config. If require pins laravel/nova: ^3.0, do not attempt it on Nova 4/5 without forking resources/js and rebuilding — you will get a blank field or a console error, not a friendly failure. Verify the constraint before committing to it in production.

Class naming. Confirm the actual field class in src/. Packages named nova-toggle-switch frequently export ToggleSwitch rather than NovaToggleSwitch, and IDE autocompletion will not save you.

Compiled assets. Nova field packages ship a dist/js/field.js. If your host app runs npm run prod on Nova's own assets, it will not rebuild third-party fields. If the shipped dist/ is stale against your Nova version, the toggle renders but does not save — check the network tab for the PUT to /nova-api/... and confirm the payload key matches your column.

Null vs false. A boolean column with nullable() will produce a three-state toggle (null / 0 / 1) that the switch cannot express. If null matters (e.g., "unset" vs "off"), do not use a toggle — use a Select with three options. Toggles lie about tri-state data.

trueValue/falseValue must match storage. Setting ->trueValue('yes')->falseValue('no') on a boolean column breaks queries silently. Match the DB column, then translate for display only.

Authorization. Toggles inherit the standard ->canSee() / ->canUpdate() gates, but bulk actions do not — re-check $request->user()->can(...) inside the action's handle().

Extension point. If the styling doesn't suit you, the cheapest fix is a two-line override: copy resources/js/components/ToggleSwitch.vue into your own field or vendor it and adjust the Tailwind classes. Do not patch vendor/ — composer update will erase it.

Debugging order when it misbehaves. (1) Is dist/js/field.js loaded? Inspect the page source for the field's script tag. (2) Does Nova's fields JS registry know the component name? A mismatch shows as "Unknown component". (3) Does the form payload contain the field key? If not, the Vue model binding is broken against your Nova version, and you are in fork territory.

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.
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels