Laravel Community Tools by Tighten
Laravel Nova icon Nova Packages
T

Toggle Switch Field

Installation Instructions

Same as most other Nova Packages

composer require davidpiesse/nova-toggle

Usage

The Toggle has all the same options as the Boolean field so you can set the values to be stored in the Model.

Toggle::make('Active')
    ->trueValue('On')
    ->falseValue('Off')
    ->showLabels()
    ->trueLabel('Yeah Buddy')
    ->falseColour('red')

In addition you can set visual parameters such as labels, size, colors and animation speed

Readme

Toggle Field

A drop in replacement for the default Boolean field

Toggle In Action

Installation

Same as most other Nova Packages

composer require davidpiesse/nova-toggle

Usage

The Toggle has all the same options as the Boolean field so you can set the values to be stored in the Model.

use Davidpiesse\NovaToggle\Toggle;
Toggle::make('Active')
    ->trueValue('On')
    ->falseValue('Off')

In addition you can set visual parameters

Labels

You can show both, or each state label

Toggle::make('Active')
    ->showLabels() //Both labels
    ->showOnlyTrueLabel() //True label only
    ->showOnlyFalseLabel() //False label only

To set the text you can use either or both of the following. You must also set the visibility of the labels as described above.

Toggle::make('Active')
    ->showLabels()
    ->trueLabel('Tru Dat')
    ->falseLabel('Nah Dawg')

The defaults are 'True' and 'False'

Size

You can set the width and height. Setting the width will auto scale the height, but you can override this with ->height(). Defaults are 60 (px) and 26 (px)

Toggle::make('Active')
    ->width(80)
    ->height(45) //To override scaling

Colors

You can set wither or both of the background colours for the Toggle. By default True is the Nova 'Success Green' [ var(--success) ] and false is a Grey 60 [ var(--60) ]

Toggle::make('Active')
    ->trueColor('pink')
    ->falseColor('#fcfcfc')

Speed

You can set the animation speed in ms with

Toggle::make('Active')
    ->speed(500)

The default is 300ms

Toggle on index

You can activate the toggle on index as well with

Toggle::make('Active')
    ->editableIndex()

Screenshots

Reviews

By Toby Evans on June 15, 2023

Good field, but has a few issues on Nova 4 and seems to have been abandoned.

By Mohamed abuassi on April 13, 2023

this package has problems with all buttons except the toggle button

Back to Top
Added 7 years ago
Last updated 3 Years Ago
Version 4.0
Composer
davidpiesse/nova-toggle
GitHub stars 86
Packagist downloads 1,083,725

Favorites

41 users favorited

Rating

4.60
(out of 5)
★★★★★
★★★★
★★★
★★
12 ratings

Brought to you by Tighten

Issues/Feature Requests Stats Package Ideas